linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] auxdisplay: ks0108: fix refcount
@ 2015-07-20 11:57 Sudip Mukherjee
  2015-07-20 11:57 ` [PATCH 2/4] auxdisplay: ks0108: start using pr_* Sudip Mukherjee
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2015-07-20 11:57 UTC (permalink / raw)
  To: Miguel Ojeda Sandonis, gregkh; +Cc: linux-kernel, Sudip Mukherjee, stable

parport_find_base() will implicitly do parport_get_port() which
increases the refcount. Then parport_register_device() will again
increment the refcount. But while unloading the module we are only
doing parport_unregister_device() decrementing the refcount only once.
We add an parport_put_port() to neutralize the effect of
parport_get_port().

Cc: <stable@vger.kernel.org> # 2.6.32+
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 drivers/auxdisplay/ks0108.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/auxdisplay/ks0108.c b/drivers/auxdisplay/ks0108.c
index 5b93852..0d75285 100644
--- a/drivers/auxdisplay/ks0108.c
+++ b/drivers/auxdisplay/ks0108.c
@@ -139,6 +139,7 @@ static int __init ks0108_init(void)
 
 	ks0108_pardevice = parport_register_device(ks0108_parport, KS0108_NAME,
 		NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
+	parport_put_port(ks0108_parport);
 	if (ks0108_pardevice == NULL) {
 		printk(KERN_ERR KS0108_NAME ": ERROR: "
 			"parport didn't register new device\n");
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] auxdisplay: ks0108: start using pr_*
  2015-07-20 11:57 [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee
@ 2015-07-20 11:57 ` Sudip Mukherjee
  2015-07-20 11:57 ` [PATCH 3/4] auxdisplay: ks0108: use min_t Sudip Mukherjee
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2015-07-20 11:57 UTC (permalink / raw)
  To: Miguel Ojeda Sandonis, gregkh; +Cc: linux-kernel, Sudip Mukherjee

Start using pr_* macros instead of using printk and in the process
define pr_fmt.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 drivers/auxdisplay/ks0108.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/auxdisplay/ks0108.c b/drivers/auxdisplay/ks0108.c
index 0d75285..30d6d0e 100644
--- a/drivers/auxdisplay/ks0108.c
+++ b/drivers/auxdisplay/ks0108.c
@@ -23,6 +23,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -132,8 +134,7 @@ static int __init ks0108_init(void)
 
 	ks0108_parport = parport_find_base(ks0108_port);
 	if (ks0108_parport == NULL) {
-		printk(KERN_ERR KS0108_NAME ": ERROR: "
-			"parport didn't find %i port\n", ks0108_port);
+		pr_err("ERROR: parport didn't find %i port\n", ks0108_port);
 		goto none;
 	}
 
@@ -141,15 +142,14 @@ static int __init ks0108_init(void)
 		NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
 	parport_put_port(ks0108_parport);
 	if (ks0108_pardevice == NULL) {
-		printk(KERN_ERR KS0108_NAME ": ERROR: "
-			"parport didn't register new device\n");
+		pr_err("ERROR: parport didn't register new device\n");
 		goto none;
 	}
 
 	result = parport_claim(ks0108_pardevice);
 	if (result != 0) {
-		printk(KERN_ERR KS0108_NAME ": ERROR: "
-			"can't claim %i parport, maybe in use\n", ks0108_port);
+		pr_err("ERROR: can't claim %i parport, maybe in use\n",
+		       ks0108_port);
 		ret = result;
 		goto registered;
 	}
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] auxdisplay: ks0108: use min_t
  2015-07-20 11:57 [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee
  2015-07-20 11:57 ` [PATCH 2/4] auxdisplay: ks0108: start using pr_* Sudip Mukherjee
@ 2015-07-20 11:57 ` Sudip Mukherjee
  2015-07-20 11:57 ` [PATCH 4/4] auxdisplay: ks0108: use new parport device model Sudip Mukherjee
  2015-07-29  6:53 ` [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee
  3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2015-07-20 11:57 UTC (permalink / raw)
  To: Miguel Ojeda Sandonis, gregkh; +Cc: linux-kernel, Sudip Mukherjee

Using min_t() is preffered than using min().

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 drivers/auxdisplay/ks0108.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/auxdisplay/ks0108.c b/drivers/auxdisplay/ks0108.c
index 30d6d0e..ce00e95 100644
--- a/drivers/auxdisplay/ks0108.c
+++ b/drivers/auxdisplay/ks0108.c
@@ -92,17 +92,19 @@ void ks0108_displaystate(unsigned char state)
 
 void ks0108_startline(unsigned char startline)
 {
-	ks0108_writedata(min(startline,(unsigned char)63) | bit(6) | bit(7));
+	ks0108_writedata(min_t(unsigned char, startline, 63) | bit(6) |
+			 bit(7));
 }
 
 void ks0108_address(unsigned char address)
 {
-	ks0108_writedata(min(address,(unsigned char)63) | bit(6));
+	ks0108_writedata(min_t(unsigned char, address, 63) | bit(6));
 }
 
 void ks0108_page(unsigned char page)
 {
-	ks0108_writedata(min(page,(unsigned char)7) | bit(3) | bit(4) | bit(5) | bit(7));
+	ks0108_writedata(min_t(unsigned char, page, 7) | bit(3) | bit(4) |
+			 bit(5) | bit(7));
 }
 
 EXPORT_SYMBOL_GPL(ks0108_writedata);
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] auxdisplay: ks0108: use new parport device model
  2015-07-20 11:57 [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee
  2015-07-20 11:57 ` [PATCH 2/4] auxdisplay: ks0108: start using pr_* Sudip Mukherjee
  2015-07-20 11:57 ` [PATCH 3/4] auxdisplay: ks0108: use min_t Sudip Mukherjee
@ 2015-07-20 11:57 ` Sudip Mukherjee
  2015-07-29  6:53 ` [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee
  3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2015-07-20 11:57 UTC (permalink / raw)
  To: Miguel Ojeda Sandonis, gregkh; +Cc: linux-kernel, Sudip Mukherjee

Modify auxdisplay driver to use the new parallel port device model.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 drivers/auxdisplay/ks0108.c | 76 ++++++++++++++++++++++++++++-----------------
 1 file changed, 47 insertions(+), 29 deletions(-)

diff --git a/drivers/auxdisplay/ks0108.c b/drivers/auxdisplay/ks0108.c
index ce00e95..b58de31 100644
--- a/drivers/auxdisplay/ks0108.c
+++ b/drivers/auxdisplay/ks0108.c
@@ -125,51 +125,69 @@ unsigned char ks0108_isinited(void)
 }
 EXPORT_SYMBOL_GPL(ks0108_isinited);
 
-/*
- * Module Init & Exit
- */
-
-static int __init ks0108_init(void)
+static void ks0108_parport_attach(struct parport *port)
 {
-	int result;
-	int ret = -EINVAL;
+	struct pardev_cb ks0108_cb;
 
-	ks0108_parport = parport_find_base(ks0108_port);
-	if (ks0108_parport == NULL) {
-		pr_err("ERROR: parport didn't find %i port\n", ks0108_port);
-		goto none;
-	}
+	if (port->base != ks0108_port)
+		return;
 
-	ks0108_pardevice = parport_register_device(ks0108_parport, KS0108_NAME,
-		NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
-	parport_put_port(ks0108_parport);
-	if (ks0108_pardevice == NULL) {
+	memset(&ks0108_cb, 0, sizeof(ks0108_cb));
+	ks0108_cb.flags = PARPORT_DEV_EXCL;
+	ks0108_pardevice = parport_register_dev_model(port, KS0108_NAME,
+						      &ks0108_cb, 0);
+	if (!ks0108_pardevice) {
 		pr_err("ERROR: parport didn't register new device\n");
-		goto none;
+		return;
 	}
-
-	result = parport_claim(ks0108_pardevice);
-	if (result != 0) {
-		pr_err("ERROR: can't claim %i parport, maybe in use\n",
+	if (parport_claim(ks0108_pardevice)) {
+		pr_err("could not claim access to parport %i. Aborting.\n",
 		       ks0108_port);
-		ret = result;
-		goto registered;
+		goto err_unreg_device;
 	}
 
 	ks0108_inited = 1;
-	return 0;
+	return;
 
-registered:
+err_unreg_device:
 	parport_unregister_device(ks0108_pardevice);
-
-none:
-	return ret;
+	ks0108_pardevice = NULL;
 }
 
-static void __exit ks0108_exit(void)
+static void ks0108_parport_detach(struct parport *port)
 {
+	if (port->base != ks0108_port)
+		return;
+
+	if (!ks0108_pardevice) {
+		pr_err("%s: already unregistered.\n", KS0108_NAME);
+		return;
+	}
+
 	parport_release(ks0108_pardevice);
 	parport_unregister_device(ks0108_pardevice);
+	ks0108_pardevice = NULL;
+}
+
+/*
+ * Module Init & Exit
+ */
+
+static struct parport_driver ks0108_parport_driver = {
+	.name = "ks0108",
+	.match_port = ks0108_parport_attach,
+	.detach = ks0108_parport_detach,
+	.devmodel = true,
+};
+
+static int __init ks0108_init(void)
+{
+	return parport_register_driver(&ks0108_parport_driver);
+}
+
+static void __exit ks0108_exit(void)
+{
+	parport_unregister_driver(&ks0108_parport_driver);
 }
 
 module_init(ks0108_init);
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] auxdisplay: ks0108: fix refcount
  2015-07-20 11:57 [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee
                   ` (2 preceding siblings ...)
  2015-07-20 11:57 ` [PATCH 4/4] auxdisplay: ks0108: use new parport device model Sudip Mukherjee
@ 2015-07-29  6:53 ` Sudip Mukherjee
  3 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2015-07-29  6:53 UTC (permalink / raw)
  To: Miguel Ojeda Sandonis, gregkh; +Cc: linux-kernel, stable

On Mon, Jul 20, 2015 at 05:27:21PM +0530, Sudip Mukherjee wrote:
> parport_find_base() will implicitly do parport_get_port() which
> increases the refcount. Then parport_register_device() will again
> increment the refcount. But while unloading the module we are only
> doing parport_unregister_device() decrementing the refcount only once.
> We add an parport_put_port() to neutralize the effect of
> parport_get_port().
> 
> Cc: <stable@vger.kernel.org> # 2.6.32+
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---
Hi Miguel,
A gentle ping.

regards
sudip

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-29  6:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-20 11:57 [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee
2015-07-20 11:57 ` [PATCH 2/4] auxdisplay: ks0108: start using pr_* Sudip Mukherjee
2015-07-20 11:57 ` [PATCH 3/4] auxdisplay: ks0108: use min_t Sudip Mukherjee
2015-07-20 11:57 ` [PATCH 4/4] auxdisplay: ks0108: use new parport device model Sudip Mukherjee
2015-07-29  6:53 ` [PATCH 1/4] auxdisplay: ks0108: fix refcount Sudip Mukherjee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).