Patch "chardev: fix error handling in cdev_device_add()" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    chardev: fix error handling in cdev_device_add()

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     chardev-fix-error-handling-in-cdev_device_add.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 8c00d5837b8354b5a7e9d1a40a07ada253728758
Author: Yang Yingliang <yangyingliang@xxxxxxxxxx>
Date:   Fri Dec 2 11:02:37 2022 +0800

    chardev: fix error handling in cdev_device_add()
    
    [ Upstream commit 11fa7fefe3d8fac7da56bc9aa3dd5fb3081ca797 ]
    
    While doing fault injection test, I got the following report:
    
    ------------[ cut here ]------------
    kobject: '(null)' (0000000039956980): is not initialized, yet kobject_put() is being called.
    WARNING: CPU: 3 PID: 6306 at kobject_put+0x23d/0x4e0
    CPU: 3 PID: 6306 Comm: 283 Tainted: G        W          6.1.0-rc2-00005-g307c1086d7c9 #1253
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
    RIP: 0010:kobject_put+0x23d/0x4e0
    Call Trace:
     <TASK>
     cdev_device_add+0x15e/0x1b0
     __iio_device_register+0x13b4/0x1af0 [industrialio]
     __devm_iio_device_register+0x22/0x90 [industrialio]
     max517_probe+0x3d8/0x6b4 [max517]
     i2c_device_probe+0xa81/0xc00
    
    When device_add() is injected fault and returns error, if dev->devt is not set,
    cdev_add() is not called, cdev_del() is not needed. Fix this by checking dev->devt
    in error path.
    
    Fixes: 233ed09d7fda ("chardev: add helper function to register char devs with a struct device")
    Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221202030237.520280-1-yangyingliang@xxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/char_dev.c b/fs/char_dev.c
index c5e6eff5a381..36479b72d278 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -544,7 +544,7 @@ int cdev_device_add(struct cdev *cdev, struct device *dev)
 	}
 
 	rc = device_add(dev);
-	if (rc)
+	if (rc && dev->devt)
 		cdev_del(cdev);
 
 	return rc;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux