Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1703813imw; Sat, 16 Jul 2022 12:48:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sFw5VfoIeuMhXEof6q271Wb36lmud7Xbgd1NdnE9q1qqadp8R/xCUYmrD4jicneFj+wv+F X-Received: by 2002:a05:6402:3047:b0:43a:9e43:95e5 with SMTP id bs7-20020a056402304700b0043a9e4395e5mr27512158edb.385.1658000912285; Sat, 16 Jul 2022 12:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658000912; cv=none; d=google.com; s=arc-20160816; b=hFqv93yJoJEIMMfS6Ts+ZKYw1QEUULP9EbhkLitDfG3riMqxeU4SuT0pfb2SGJ9+1U DEXqmrQ2BxkfJEeHDhbCUDh6hT0dX8A3DROAeCGPPOZKOggY4ABcErfZ6HJZw2EoLsgN hGplFxWviEwdP9ySsONzXj6kQDJw3YtJoKOBwKbSfkuFQVjTkR0eHbylAPbBmK+7z3pA JGlEe/HzVz9e4f23JqvBGqqoGqA7Q/Llx+QaQe7YBr7W9VAOHVOHdztHiq7qE5j9qMKf 2vBvx71aHAP+VQSA1tge6vvBYMVDfJiENOHOvjXzaYFik4EIrIZfoFd6lf9Gz8ae21+r OPyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DrrK3fW/0JCsLeYoJVa39wcnT6vak1RAjg7ztJAVd8U=; b=kzzlyR2ZVXdGBpkFMjYuxzS03ceGFM01jLnT8zwdMSF24lcgm76H/na5nRSqC7Ngxi 3M8ZZvzd+6u2xbRkHpNeLFedkcoZ9cgBJRJFqOtMStToekwYL6nhRv36gFkp1k7lTiSm bEsd+0dPMYoj7uJ2SkAkRm1yt3BF6bIl5DA4UVm4Z9gMUHQ7KBW64EohX07ZI4U8rjYL 38rA1I4xyB7jo1GQiNzR131PWTOF+Se3tLvv20V/TadENrMVjV2T8fKLDb/PMm3Ee6BW zh6I9Q08OHpVgLAkCnMaGaIvNRNUxo3gW5BToLbfvrqSOp2vygNIhYCFs4/IfxZsmkFU Hfxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FI5KRhwe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr5-20020a1709073f8500b0072af3c24981si9051251ejc.425.2022.07.16.12.48.07; Sat, 16 Jul 2022 12:48:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FI5KRhwe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230271AbiGPTXn (ORCPT + 99 others); Sat, 16 Jul 2022 15:23:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbiGPTXm (ORCPT ); Sat, 16 Jul 2022 15:23:42 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 392F517E37; Sat, 16 Jul 2022 12:23:41 -0700 (PDT) Received: from mercury (unknown [185.209.196.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sre) by madras.collabora.co.uk (Postfix) with ESMTPSA id 8DB4566016A1; Sat, 16 Jul 2022 20:23:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1657999419; bh=Hzk9ep426NKaWWxmuzF3OGnr6jyChpNw7cVZGou7UbU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FI5KRhwedJm46o+g5HPlupVcJO5uiEfzDGo99BFMBPOvW6H0kVILoaGwxkuaMkSji tXitWs97JkxCvEf+Ycgc/4VuraZYSJj9HNGF03GhoRBYrUuPxSoyH+7F8dJLCdBJIQ rKtp5Zrxyc0hfriHZ8LDPuvJDXoSAutOUW9Y1xfIBzQGHvQtIskDB1DQ+dlPH1iT2q MguBsYjvH2WgKFpZluUST17eiTv7SBOf6JYJmwb31cxcD6vBsWDz16LgD+DNA9oBKX PH5bRzdydUWTh5i+q4k7XtgkNSl+GUZk9yR/vRUCmdXceW/wgIJAxxVfMja5pWXMQc Q0kdr1jkS466A== Received: by mercury (Postfix, from userid 1000) id DC9DE106069E; Sat, 16 Jul 2022 21:23:36 +0200 (CEST) Date: Sat, 16 Jul 2022 21:23:36 +0200 From: Sebastian Reichel To: Zheyu Ma Cc: t.schramm@manjaro.org, linux-pm@vger.kernel.org, Linux Kernel Mailing List Subject: Re: [BUG] power: supply: cw2015: Found a bug when removing the module Message-ID: <20220716192336.ccxwopvaurtcef4p@mercury.elektranox.org> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="lgwp5xb6gbex7tbk" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --lgwp5xb6gbex7tbk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Sat, Jul 16, 2022 at 04:50:08PM +0800, Zheyu Ma wrote: > I found a bug in the cw2015 driver. >=20 > When I insmod the kernel module, I get the following log: >=20 > [ 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 pr= ofile > [ 199.486086] cw2015 0-0010: Failed to get supply state: -19 >=20 > And when I remove the module, I got the following warning: >=20 > [ 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] > [ 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 >=20 > 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 yo= u. >=20 > regards, >=20 > Zheyu Ma Thanks, -- Sebastian --lgwp5xb6gbex7tbk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmLTEDUACgkQ2O7X88g7 +pq6pw/+N0oP/9DNfQ+aQ3gDTnCOlfh5BTwOTsXJf5psMgErsswM1gtp0LcN0nxZ LhZhTBUslXwAerbXMFN+FKqL1L1KNH/Mu41EmUY6isH2XGD/WmVQxk6NvGSnmq40 3JMgkMK0FvSdILng9j95hw/AkKOJFTIZkwcLLiWekTfhVjJUcqJSIilULCxQBYld WGsWqsONpA1NNkE3QYsOzXbl3SHDAtQXedetKgYk1T3ACku1/sL/0VTH/GMJAftv YlQNWpGCiuujDpJQLyXzPa989oSepDEhaTD+ZMkxwiGsQ22uzlWyGRCMCn0bWnie qs37MkS+CqVF/PA/4vvWzWsjWek6SMw0Q7rVgcaZSjYoinZnJwJj3uajRAZe7/gA vpxxI2Tt8GSKv9harrH1xKVbNkHWEM8L996oWNPDSJ8odkb8jnvBexej6zhuhUGp 5qScXd9cRdpHgYwSfmIw8pF27+RRatmYInu3qbCJUlsy6fG8s3d+BlE0Bj+ZT0Wt Lz7Am8u1gPgau0tJTFpC8kJQwRQk4m48QznR7ctcVUbw7cd7U/pxDpFA/YTsq4rP C59vLtYae9YR5j/Lm0BUMv3k3I+lJixq6EDpaXuC1GKwKthtuXz9CyRHN24hBsQz 8lfEVdpchzREQViVMgUez6WYJyGokeNgmAc3tmdZJygixJ9FrTY= =5PWL -----END PGP SIGNATURE----- --lgwp5xb6gbex7tbk--