]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
drivers/w1/w1_int.c: call put_device if device_register fails
authorLevente Kurusa <levex@linux.com>
Thu, 26 Jun 2014 00:43:24 +0000 (10:43 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 27 Jun 2014 04:21:53 +0000 (14:21 +1000)
Currently, memsetting and kfreeing the device is bad behaviour.  The
device will have a reference count of 1 and hence can cause trouble
because it has kfree'd.  Proper way to handle a failed device_register is
to call put_device right after it fails.

Signed-off-by: Levente Kurusa <levex@linux.com>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/w1/w1_int.c

index 47249a30eae38e4c80078086c3a1b33309e6eeb9..20f766afa4c7d7b8116565687541f84184fe61f4 100644 (file)
@@ -91,8 +91,7 @@ static struct w1_master *w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
        err = device_register(&dev->dev);
        if (err) {
                pr_err("Failed to register master device. err=%d\n", err);
-               memset(dev, 0, sizeof(struct w1_master));
-               kfree(dev);
+               put_device(&dev->dev);
                dev = NULL;
        }