i2c: dev: check return value when calling dev_set_name()
commit993eb48fa1
upstream. If dev_set_name() fails, the dev_name() is null, check the return value of dev_set_name() to avoid the null-ptr-deref. Fixes:1413ef638a
("i2c: dev: Fix the race between the release of i2c_dev and cdev") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
6b4bf97587
commit
2f345bb14a
@ -668,16 +668,21 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy)
|
|||||||
i2c_dev->dev.class = i2c_dev_class;
|
i2c_dev->dev.class = i2c_dev_class;
|
||||||
i2c_dev->dev.parent = &adap->dev;
|
i2c_dev->dev.parent = &adap->dev;
|
||||||
i2c_dev->dev.release = i2cdev_dev_release;
|
i2c_dev->dev.release = i2cdev_dev_release;
|
||||||
dev_set_name(&i2c_dev->dev, "i2c-%d", adap->nr);
|
|
||||||
|
res = dev_set_name(&i2c_dev->dev, "i2c-%d", adap->nr);
|
||||||
|
if (res)
|
||||||
|
goto err_put_i2c_dev;
|
||||||
|
|
||||||
res = cdev_device_add(&i2c_dev->cdev, &i2c_dev->dev);
|
res = cdev_device_add(&i2c_dev->cdev, &i2c_dev->dev);
|
||||||
if (res) {
|
if (res)
|
||||||
put_i2c_dev(i2c_dev, false);
|
goto err_put_i2c_dev;
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr);
|
pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_put_i2c_dev:
|
||||||
|
put_i2c_dev(i2c_dev, false);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int i2cdev_detach_adapter(struct device *dev, void *dummy)
|
static int i2cdev_detach_adapter(struct device *dev, void *dummy)
|
||||||
|
Reference in New Issue
Block a user