All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Zheyu Ma <zheyuma97@gmail.com>
Cc: t.schramm@manjaro.org, linux-pm@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] power: supply: cw2015: Found a bug when removing the module
Date: Sat, 16 Jul 2022 21:23:36 +0200	[thread overview]
Message-ID: <20220716192336.ccxwopvaurtcef4p@mercury.elektranox.org> (raw)
In-Reply-To: <CAMhUBjkMyRP2iyMpovN7=GFP2SSpt+Na453RR6nNSBeyQR6oww@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2136 bytes --]

Hi,

On Sat, Jul 16, 2022 at 04:50:08PM +0800, Zheyu Ma wrote:
> 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.

Indeed that seems to happen. Easiest solution is to remove the call
to power_supply_put_battery_info(), because power_supply_get_battery_info()
is now using device managed memory allocation for everything and memory
will be free'd automatically when the device is removed. Can one of you
send a patch for that, since I cannot test it due to lack of hardware?

Also while at it maybe use 'devm_delayed_work_autocancel()' instead
of 'INIT_DELAYED_WORK', so that all resources are device managed and
the remove function can be removed.

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

Thanks,

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2022-07-16 19:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-16  8:50 [BUG] power: supply: cw2015: Found a bug when removing the module Zheyu Ma
2022-07-16 19:23 ` Sebastian Reichel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220716192336.ccxwopvaurtcef4p@mercury.elektranox.org \
    --to=sebastian.reichel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=t.schramm@manjaro.org \
    --cc=zheyuma97@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.