Message ID | 20241211031829.2257107-1-make_ruc2021@163.com (mailing list archive) |
---|---|
State | New |
Delegated to: | Chanwoo Choi |
Headers | show |
Series | PM / devfreq: Check dev_set_name() return value | expand |
>It's possible that dev_set_name() returns -ENOMEM. We could catch and >handle it by adding dev_set_name() return value check. > >Cc: stable@vger.kernel.org >Fixes: 775fa8c3aa22 ("PM / devfreq: Simplify the sysfs name of devfreq-event device") >Signed-off-by: Ma Ke <make_ruc2021@163.com> >--- > drivers/devfreq/devfreq-event.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > >diff --git a/drivers/devfreq/devfreq-event.c b/drivers/devfreq/devfreq-event.c >index 3ebac2496679..9479fbe71eda 100644 >--- a/drivers/devfreq/devfreq-event.c >+++ b/drivers/devfreq/devfreq-event.c >@@ -328,7 +328,10 @@ struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev, > edev->dev.class = devfreq_event_class; > edev->dev.release = devfreq_event_release_edev; > >- dev_set_name(&edev->dev, "event%d", atomic_inc_return(&event_no)); >+ ret = dev_set_name(&edev->dev, "event%d", atomic_inc_return(&event_no)); >+ if (ret) >+ return ERR_PTR(-ENOMEM); >+ NACK. 1. edev is not handled. 2. although dev_set_name returns -ENOMEM or 0 today, you don't know if it will return something else in the future. Use what it has returned. Cheers, MyungJoo > ret = device_register(&edev->dev); > if (ret < 0) { > put_device(&edev->dev); >-- >2.25.1
diff --git a/drivers/devfreq/devfreq-event.c b/drivers/devfreq/devfreq-event.c index 3ebac2496679..9479fbe71eda 100644 --- a/drivers/devfreq/devfreq-event.c +++ b/drivers/devfreq/devfreq-event.c @@ -328,7 +328,10 @@ struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev, edev->dev.class = devfreq_event_class; edev->dev.release = devfreq_event_release_edev; - dev_set_name(&edev->dev, "event%d", atomic_inc_return(&event_no)); + ret = dev_set_name(&edev->dev, "event%d", atomic_inc_return(&event_no)); + if (ret) + return ERR_PTR(-ENOMEM); + ret = device_register(&edev->dev); if (ret < 0) { put_device(&edev->dev);
It's possible that dev_set_name() returns -ENOMEM. We could catch and handle it by adding dev_set_name() return value check. Cc: stable@vger.kernel.org Fixes: 775fa8c3aa22 ("PM / devfreq: Simplify the sysfs name of devfreq-event device") Signed-off-by: Ma Ke <make_ruc2021@163.com> --- drivers/devfreq/devfreq-event.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)