]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drivers/w1/w1_int.c: call put_device if device_register fails
authorLevente Kurusa <levex@linux.com>
Sat, 17 May 2014 13:19:33 +0000 (23:19 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Mon, 19 May 2014 07:35:07 +0000 (17:35 +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 9b084db739c745b9940cd68ee268542f76820695..3aaa15f6b7e9cd8e998314af7374a22fbf637228 100644 (file)
@@ -92,9 +92,8 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
        err = device_register(&dev->dev);
        if (err) {
                printk(KERN_ERR "Failed to register master device. err=%d\n", err);
-               memset(dev, 0, sizeof(struct w1_master));
-               kfree(dev);
-               dev = NULL;
+               put_device(&dev->dev);
+               return NULL;
        }
 
        return dev;