All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zoltán Böszörményi" <zboszor@pr.hu>
To: linux-kernel@vger.kernel.org
Cc: linux-usb@vger.kernel.org, linux-watchdog@vger.kernel.org,
	linux-i2c@vger.kernel.org,
	"Paul Menzel" <paulepanter@users.sourceforge.net>,
	"Christian Fetzer" <fetzer.ch@gmail.com>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Nehal Shah" <nehal-bakulchandra.shah@amd.com>,
	"Tim Small" <tim@seoss.co.uk>,
	"Guenter Roeck" <linux@roeck-us.net>,
	kernel@ekass.net, wim@iguana.be, jlayton@poochiereds.net,
	marc.2377@gmail.com, cshorler@googlemail.com, wsa@the-dreams.de,
	regressions@leemhuis.info, "Zoltán Böszörményi" <zboszor@pr.hu>
Subject: [PATCH 1/5] Extend the request_region() infrastructure
Date: Wed, 21 Jun 2017 05:53:45 +0200	[thread overview]
Message-ID: <20170621035349.4125-2-zboszor@pr.hu> (raw)
In-Reply-To: <20170621035349.4125-1-zboszor@pr.hu>

Add a new IORESOURCE_ALLOCATED flag that is automatically used
when alloc_resource() is used internally in kernel/resource.c
and free_resource() now takes this flag into account.

The core of __request_region() was factored out into a new function
called __request_declared_region() that needs struct resource *
instead of the (start, n, name) triplet.

These changes allow using statically declared struct resource
data coupled with the pre-existing DEFINE_RES_IO_NAMED() static
initializer macro. The new macro exploiting
__request_declared_region() is request_declared_muxed_region()

Signed-off-by: Zoltán Böszörményi <zboszor@pr.hu>
---
 include/linux/ioport.h |  5 +++++
 kernel/resource.c      | 55 +++++++++++++++++++++++++++++++++++---------------
 2 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 6230064..a3c4e08 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -52,6 +52,7 @@ struct resource {
 #define IORESOURCE_MEM_64	0x00100000
 #define IORESOURCE_WINDOW	0x00200000	/* forwarded by bridge */
 #define IORESOURCE_MUXED	0x00400000	/* Resource is software muxed */
+#define IORESOURCE_ALLOCATED	0x00800000	/* Resource was allocated */
 
 #define IORESOURCE_EXT_TYPE_BITS 0x01000000	/* Resource extended types */
 #define IORESOURCE_SYSRAM	0x01000000	/* System RAM (modifier) */
@@ -216,12 +217,16 @@ static inline bool resource_contains(struct resource *r1, struct resource *r2)
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)		__request_region(&ioport_resource, (start), (n), (name), 0)
 #define request_muxed_region(start,n,name)	__request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)
+#define request_declared_muxed_region(res)	__request_declared_region(&ioport_resource, (res), IORESOURCE_MUXED)
 #define __request_mem_region(start,n,name, excl) __request_region(&iomem_resource, (start), (n), (name), excl)
 #define request_mem_region(start,n,name) __request_region(&iomem_resource, (start), (n), (name), 0)
 #define request_mem_region_exclusive(start,n,name) \
 	__request_region(&iomem_resource, (start), (n), (name), IORESOURCE_EXCLUSIVE)
 #define rename_region(region, newname) do { (region)->name = (newname); } while (0)
 
+extern struct resource * __request_declared_region(struct resource *,
+					struct resource *res, int flags);
+
 extern struct resource * __request_region(struct resource *,
 					resource_size_t start,
 					resource_size_t n,
diff --git a/kernel/resource.c b/kernel/resource.c
index 9b5f044..220f695 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -184,6 +184,9 @@ static void free_resource(struct resource *res)
 	if (!res)
 		return;
 
+	if (!(res->flags & IORESOURCE_ALLOCATED))
+		return;
+
 	if (!PageSlab(virt_to_head_page(res))) {
 		spin_lock(&bootmem_resource_lock);
 		res->sibling = bootmem_resource_free;
@@ -210,6 +213,8 @@ static struct resource *alloc_resource(gfp_t flags)
 	else
 		res = kzalloc(sizeof(struct resource), flags);
 
+	res->flags = IORESOURCE_ALLOCATED;
+
 	return res;
 }
 
@@ -1117,26 +1122,15 @@ resource_size_t resource_alignment(struct resource *res)
 static DECLARE_WAIT_QUEUE_HEAD(muxed_resource_wait);
 
 /**
- * __request_region - create a new busy resource region
+ * __request_declared_region - create a new busy resource region
  * @parent: parent resource descriptor
- * @start: resource start address
- * @n: resource region size
- * @name: reserving caller's ID string
+ * @res: child resource descriptor
  * @flags: IO resource flags
  */
-struct resource * __request_region(struct resource *parent,
-				   resource_size_t start, resource_size_t n,
-				   const char *name, int flags)
+struct resource * __request_declared_region(struct resource *parent,
+				   struct resource *res, int flags)
 {
 	DECLARE_WAITQUEUE(wait, current);
-	struct resource *res = alloc_resource(GFP_KERNEL);
-
-	if (!res)
-		return NULL;
-
-	res->name = name;
-	res->start = start;
-	res->end = start + n - 1;
 
 	write_lock(&resource_lock);
 
@@ -1166,13 +1160,42 @@ struct resource * __request_region(struct resource *parent,
 			continue;
 		}
 		/* Uhhuh, that didn't work out.. */
-		free_resource(res);
 		res = NULL;
 		break;
 	}
 	write_unlock(&resource_lock);
 	return res;
 }
+EXPORT_SYMBOL(__request_declared_region);
+
+/**
+ * __request_region - create a new busy resource region
+ * @parent: parent resource descriptor
+ * @start: resource start address
+ * @n: resource region size
+ * @name: reserving caller's ID string
+ * @flags: IO resource flags
+ */
+struct resource * __request_region(struct resource *parent,
+				   resource_size_t start, resource_size_t n,
+				   const char *name, int flags)
+{
+	struct resource *res = alloc_resource(GFP_KERNEL);
+
+	if (!res)
+		return NULL;
+
+	res->name = name;
+	res->start = start;
+	res->end = start + n - 1;
+
+	if (!__request_declared_region(parent, res, flags)) {
+		free_resource(res);
+		res = NULL;
+	}
+
+	return res;
+}
 EXPORT_SYMBOL(__request_region);
 
 /**
-- 
2.9.4

  reply	other threads:[~2017-06-21  4:07 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<20170401110223.12056-1-zboszor@pr.hu>
2017-04-03  7:51 ` [PATCH 0/3 v2] Fix regression in the sp5100_tco driver Zoltan Boszormenyi
2017-04-03  7:51   ` [PATCH 1/3 v2] usb: pci-quirks: Add a common mutex for the I/O port pair of SB800 Zoltan Boszormenyi
2017-06-20 14:12     ` [1/3, " Guenter Roeck
2017-04-03  7:51   ` [PATCH 2/3 v2] i2c: i2c-piix4: Use the common mutex Zoltan Boszormenyi
2017-04-03  7:51     ` Zoltan Boszormenyi
2017-04-19 18:43     ` Wolfram Sang
2017-04-03  7:51   ` [PATCH 3/3 v2] watchdog: sp5100_tco: " Zoltan Boszormenyi
2017-04-03  7:51     ` Zoltan Boszormenyi
2017-06-21  3:53   ` [PATCH 0/5 v3] Fix sp5100_tco watchdog driver regression Zoltán Böszörményi
2017-06-21  3:53     ` Zoltán Böszörményi [this message]
2017-06-21  3:53     ` [PATCH 2/5] Modify behaviour of request_*muxed_region() Zoltán Böszörményi
2017-06-21  3:53     ` [PATCH 3/5] usb: pci-quirks: Protect the I/O port pair of SB800 Zoltán Böszörményi
2017-06-21  3:53     ` [PATCH 4/5] i2c: i2c-piix4: Use request_declared_muxed_region() Zoltán Böszörményi
2017-06-21  3:53     ` [PATCH 5/5] watchdog: sp5100_tco: " Zoltán Böszörményi
2017-06-21  3:53       ` Zoltán Böszörményi
2017-06-21 15:09       ` Guenter Roeck
2017-06-22 13:21     ` [PATCH 0/5 v4] Fix sp5100_tco watchdog driver regression Zoltán Böszörményi
2017-06-22 13:21       ` [PATCH 1/5 v2] Extend the request_region() infrastructure Zoltán Böszörményi
2017-07-14  8:33         ` Boszormenyi Zoltan
2017-07-14  8:33           ` Boszormenyi Zoltan
2017-07-14  8:33           ` Boszormenyi Zoltan
2017-06-22 13:21       ` [PATCH 2/5 v2] Modify behaviour of request_*muxed_region() Zoltán Böszörményi
2017-07-08 15:37         ` [2/5,v2] " Guenter Roeck
2017-07-08 15:37           ` Guenter Roeck
2017-06-22 13:21       ` [PATCH 3/5 v4] usb: pci-quirks: Protect the I/O port pair of SB800 Zoltán Böszörményi
2017-06-22 13:21         ` Zoltán Böszörményi
2017-07-14  8:34         ` Boszormenyi Zoltan
2017-07-14  8:34           ` Boszormenyi Zoltan
2017-07-14  8:34           ` Boszormenyi Zoltan
2017-07-14 11:36           ` Greg Kroah-Hartman
2017-07-14 11:36             ` Greg Kroah-Hartman
2017-07-14 11:36             ` Greg Kroah-Hartman
2017-06-22 13:21       ` [PATCH 4/5 v4] i2c: i2c-piix4: Use request_declared_muxed_region() Zoltán Böszörményi
2017-06-22 13:21       ` [PATCH 5/5 v4] watchdog: sp5100_tco: " Zoltán Böszörményi
2017-07-14  8:34         ` Boszormenyi Zoltan
2017-07-14  8:34           ` Boszormenyi Zoltan
2017-07-14  8:34           ` Boszormenyi Zoltan
2017-07-06  7:50       ` [PATCH 0/5 v4] Fix sp5100_tco watchdog driver regression Boszormenyi Zoltan
2017-07-06  7:50         ` Boszormenyi Zoltan
2017-07-07  2:09         ` Marcelo "Marc" Ranolfi
     [not found]           ` <CAETC-g_YF7TWv+LNrNQrX9AY_-iepCeE0EmCKWYF4VyQzRY+UQ@mail.gmail.com>
2017-07-07  2:26             ` Marcelo "Marc" Ranolfi
2017-04-01 10:06 [PATCH 0/3] " Zoltán Böszörményi
2017-04-01 10:06 ` [PATCH 1/3] usb: pci-quirks: Add a header for SB800 I/O ports and mutex for locking Zoltán Böszörményi
2017-04-01 10:06 ` [PATCH 3/3] watchdog: sp5100_tco: Synchronize I/O port accesses Zoltán Böszörményi
2017-04-01 11:02 ` [PATCH 0/3, resend] Fix sp5100_tco watchdog driver regression Zoltan Boszormenyi
2017-04-01 11:02   ` [PATCH 1/3] usb: pci-quirks: Add a header for SB800 I/O ports and mutex for locking Zoltan Boszormenyi
2017-04-01 13:59     ` Greg KH
2017-04-01 14:40       ` Alan Stern
2017-04-01 14:40         ` Alan Stern
2017-04-01 15:09         ` Boszormenyi Zoltan
2017-04-01 15:09           ` Boszormenyi Zoltan
2017-04-01 15:07       ` Boszormenyi Zoltan
2017-04-01 15:07         ` Boszormenyi Zoltan
2017-04-01 11:02   ` [PATCH 3/3] watchdog: sp5100_tco: Synchronize I/O port accesses Zoltan Boszormenyi
2017-04-01 11:08 ` [PATCH 2/3] i2c: i2c-piix4: Synchronize I/O port accesses with the SB800 USB quirk Zoltan Boszormenyi
2017-04-01 11:08   ` Zoltan Boszormenyi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170621035349.4125-2-zboszor@pr.hu \
    --to=zboszor@pr.hu \
    --cc=cshorler@googlemail.com \
    --cc=fetzer.ch@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=jlayton@poochiereds.net \
    --cc=kernel@ekass.net \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=marc.2377@gmail.com \
    --cc=nehal-bakulchandra.shah@amd.com \
    --cc=paulepanter@users.sourceforge.net \
    --cc=regressions@leemhuis.info \
    --cc=tim@seoss.co.uk \
    --cc=wim@iguana.be \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.