[BUG] power: supply: cw2015: Found a bug when removing the module

From: Zheyu Ma
Date: Sat Jul 16 2022 - 04:50:31 EST


Hello,

I found a bug in the cw2015 driver.

When I insmod the kernel module, I get the following log:

[ 199.445154] cw2015 0-0010: probe
[ 199.445447] cw2015 0-0010: No battery-profile found, using current
flash contents
[ 199.447198] cw2015 0-0010: Can't check current battery profile, no
profile provided
[ 199.448577] cw2015 0-0010: No monitored battery, some properties
will be missing
[ 199.449556] i2c-core: driver [cw2015] registered
[ 199.482970] cw2015 0-0010: No profile specified, continuing without profile
[ 199.486086] cw2015 0-0010: Failed to get supply state: -19

And when I remove the module, I got the following warning:

[ 200.470198] cw2015 0-0010: remove
[ 200.471445] ------------[ cut here ]------------
[ 200.472752] WARNING: CPU: 0 PID: 413 at drivers/base/devres.c:1058
devm_kfree+0x2a8/0x330
[ 200.478314] RIP: 0010:devm_kfree+0x2a8/0x330
[ 200.485019] Call Trace:
[ 200.485226] <TASK>
[ 200.485405] ? power_supply_put_battery_info+0xc2/0xe0
[ 200.486169] cw_bat_remove+0x89/0xa0 [cw2015_battery]
[ 200.486570] i2c_device_remove+0x181/0x1f0

I think the problem is that the driver fails to call the function
power_supply_get_battery_info(). However, when removing the module,
the driver executes power_supply_put_battery_info(), causing a
warning.

Since I'm not familiar with this driver, I will just report the bug to you.

regards,

Zheyu Ma