[PATCH v2 2/2] ppdev: return proper error values from attach

From: Sudip Mukherjee
Date: Wed Apr 08 2015 - 09:30:38 EST


As of now, parport_register_driver() never fails, so even if
device_create() fails for some reason we will still think that the
module has initialized properly.
lets start using attach_ret and return the proper return value from
device_create(), so that if device_create fails for some reason then
module_init will also fail.

Signed-off-by: Sudip Mukherjee <sudip@xxxxxxxxxxxxxxx>
---
drivers/char/ppdev.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index ae0b42b..ed38071 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -748,10 +748,14 @@ static const struct file_operations pp_fops = {
.release = pp_release,
};

-static void pp_attach(struct parport *port)
+static int pp_attach(struct parport *port)
{
- device_create(ppdev_class, port->dev, MKDEV(PP_MAJOR, port->number),
- NULL, "parport%d", port->number);
+ struct device *dev;
+
+ dev = device_create(ppdev_class, port->dev,
+ MKDEV(PP_MAJOR, port->number), NULL,
+ "parport%d", port->number);
+ return PTR_ERR_OR_ZERO(dev);
}

static void pp_detach(struct parport *port)
@@ -761,7 +765,7 @@ static void pp_detach(struct parport *port)

static struct parport_driver pp_driver = {
.name = CHRDEV,
- .attach = pp_attach,
+ .attach_ret = pp_attach,
.detach = pp_detach,
};

--
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/