Skip to content

Commit eb8d3c6

Browse files
ozbenhgregkh
authored andcommitted
devres: WARN() and return, don't crash on device_del() of uninitialized device
I just debugged an obscure crash caused by a device_del() of a all NULL'd out struct device (in usb-serial) and found that a patch like this one would have saved me time (in addition to improved chances of a bug report from users hitting similar driver bugs). [akpm@linux-foundation.org: cleanup] Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Kay Sievers <kay.sievers@vrfy.org> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 81e4e1b commit eb8d3c6

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎drivers/base/devres.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ int devres_release_all(struct device *dev)
428428
{
429429
unsigned long flags;
430430

431+
/* Looks like an uninitialized device structure */
432+
if (WARN_ON(dev->devres_head.next == NULL))
433+
return -ENODEV;
431434
spin_lock_irqsave(&dev->devres_lock, flags);
432435
return release_nodes(dev, dev->devres_head.next, &dev->devres_head,
433436
flags);

0 commit comments

Comments
 (0)