power: supply: cw2015: Fix potential null-ptr-deref in cw_bat_probe()
Subsystems (2)
PATCH 1/1 power: supply: cw2015: Fix potential null-ptr-deref in cw_bat_probe()
cw_bat_probe() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:
cw_bat_probe()
create_singlethread_workqueue() # failed, cw_bat->wq is NULL
queue_delayed_work()
queue_delayed_work_on()
__queue_delayed_work() # warning here, but continue
__queue_work() # access wq->flags, null-ptr-derefCheck the ret value and return -ENOMEM if it is NULL.
Fixes b4c7715c10c1 ("power: supply: add CellWise cw2015 fuel gauge driver")
Signed-off-by Shang XiaoJing <[email protected]>
--- drivers/power/supply/cw2015_battery.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/power/supply/cw2015_battery.c +3 -0
@@ -699,6 +699,9 @@ static int cw_bat_probe(struct i2c_client *client) } cw_bat->battery_workqueue =create_singlethread_workqueue ("rk_battery" ); +if (!cw_bat->battery_workqueue) +return -ENOMEM ; +devm_delayed_work_autocancel (&client->dev, &cw_bat->battery_delay_work, cw_bat_work); queue_delayed_work(cw_bat->battery_workqueue,
Signature · 1 line
2.17.1
Hi,
Quoted 10 lines · Shang XiaoJing
cw_bat_probe()callscreate_singlethread_workqueue()and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:
cw_bat_probe()create_singlethread_workqueue() # failed, cw_bat->wq is NULL queue_delayed_work() queue_delayed_work_on() __queue_delayed_work() # warning here, but continue __queue_work() # access wq->flags, null-ptr-deref
Quoted 5 lines
Check the ret value and return
-ENOMEMif it is NULL.Fixes b4c7715c10c1 ("power: supply: add CellWise cw2015 fuel gauge driver")Signed-off-by Shang XiaoJing <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 20 lines
drivers/power/supply/cw2015_battery.c | 3 +++ 1 file changed, 3 insertions(+)drivers/power/supply/cw2015_battery.c +3
-0@@ -699,6 +699,9 @@ static int cw_bat_probe(struct i2c_client *client) } cw_bat->battery_workqueue =create_singlethread_workqueue ("rk_battery" ); +if (!cw_bat->battery_workqueue) +return -ENOMEM ; +devm_delayed_work_autocancel (&client->dev, &cw_bat->battery_delay_work, cw_bat_work); queue_delayed_work(cw_bat->battery_workqueue,Signature · 1 line
2.17.1