lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 22 Nov 2017 13:07:32 -0800
From:   Matthew Wilcox <willy@...radead.org>
To:     linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Cc:     Matthew Wilcox <mawilcox@...rosoft.com>
Subject: [PATCH 55/62] firewire: Remove call to idr_preload

From: Matthew Wilcox <mawilcox@...rosoft.com>

core-cdev uses a spinlock to protect several elements, including the IDR.
Rather than reusing the IDR's spinlock for all of this, preallocate the
necessary memory by allocating a NULL pointer and then replace it with
the resource pointer once we have the spinlock.

Signed-off-by: Matthew Wilcox <mawilcox@...rosoft.com>
---
 drivers/firewire/core-cdev.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index a301fcf46e88..52c22c39744e 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -486,28 +486,24 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
 static int add_client_resource(struct client *client,
 			       struct client_resource *resource, gfp_t gfp_mask)
 {
-	bool preload = gfpflags_allow_blocking(gfp_mask);
 	unsigned long flags;
 	int ret;
 
-	if (preload)
-		idr_preload(gfp_mask);
-	spin_lock_irqsave(&client->lock, flags);
+	ret = idr_alloc(&client->resource_idr, NULL, 0, 0, gfp_mask);
+	if (ret < 0)
+		return ret;
 
-	if (client->in_shutdown)
+	spin_lock_irqsave(&client->lock, flags);
+	if (client->in_shutdown) {
+		idr_remove(&client->resource_idr, ret);
 		ret = -ECANCELED;
-	else
-		ret = idr_alloc(&client->resource_idr, resource, 0, 0,
-				GFP_NOWAIT);
-	if (ret >= 0) {
+	} else {
+		idr_replace(&client->resource_idr, resource, ret);
 		resource->handle = ret;
 		client_get(client);
 		schedule_if_iso_resource(resource);
 	}
-
 	spin_unlock_irqrestore(&client->lock, flags);
-	if (preload)
-		idr_preload_end();
 
 	return ret < 0 ? ret : 0;
 }
-- 
2.15.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ