From patchwork Thu Dec 7 14:09:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13483334 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A3710E9 for ; Thu, 7 Dec 2023 06:09:43 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rBF4P-0001Zz-Nd; Thu, 07 Dec 2023 15:09:41 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBF4O-00ECj1-Uk; Thu, 07 Dec 2023 15:09:40 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1rBF4O-00FvTM-Lc; Thu, 07 Dec 2023 15:09:40 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, linux-kbuild@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 1/4] hwmon: (smsc47m1) Mark driver struct with __refdata to prevent section mismatch Date: Thu, 7 Dec 2023 15:09:29 +0100 Message-ID: <57977a88a9b99b6555b227aa4994ac3df10c6490.1701957840.git.u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1297; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=/kNNaHtUk+dPToZUrilhi4B89ztEfaUkeR7o03Fm/4E=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlcdIZvOjHjx/XEjX+arETCYDA73eJtSqmqj0Dz 26v/YG4d6aJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZXHSGQAKCRCPgPtYfRL+ TvvcCACfE8f8CzaqUU2FtRkkhLzNIoQO9y6pW25HeVzLc4yMT3HVDScvgi68pwQ5Pg9/u6rpWjS PPHej5bpYgWwuAUjpJwGDTVVa656Z+AQMtQzwpQyrQsJlHJ1nmj1PLftnKF6if+zpOelsm/f7Lu f+qD+ERPUF0+j9UU2LEobrKopVMR/Dpr/MGFNnzT0PKbTif/0yiAtWBki4Kg677nXbwZQKz9GWL 6YSmiVFcCs27Kuf6KHy5/Dtw57qCbOgjWTPNZFjWg6JvpYnRMFNcNMe9iuxMpcoLB3TAvdF7TCR 4gb9/gH6nN7KUdMYC0s8wrQ+ifuQCwajvin1YLXGAoxYrCuq X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-hwmon@vger.kernel.org As described in the added code comment, a reference to .exit.text is ok for drivers registered via module_platform_driver_probe(). Make this explicit to prevent the following section mismatch warning WARNING: modpost: drivers/hwmon/smsc47m1: section mismatch in reference: smsc47m1_driver+0x8 (section: .data) -> smsc47m1_remove (section: .exit.text) that triggers on an allmodconfig W=1 build. Signed-off-by: Uwe Kleine-König --- drivers/hwmon/smsc47m1.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 37531b5c8254..29ea8fb4f353 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -850,7 +850,13 @@ static int __exit smsc47m1_remove(struct platform_device *pdev) return 0; } -static struct platform_driver smsc47m1_driver = { +/* + * smsc47m1_remove() lives in .exit.text. For drivers registered via + * module_platform_driver_probe() this ok because they cannot get unbound at + * runtime. The driver needs to be marked with __refdata, otherwise modpost + * triggers a section mismatch warning. + */ +static struct platform_driver smsc47m1_driver __refdata = { .driver = { .name = DRVNAME, }, From patchwork Thu Dec 7 14:09:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13483335 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20D9010FD for ; Thu, 7 Dec 2023 06:09:44 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rBF4P-0001a0-Nc; Thu, 07 Dec 2023 15:09:41 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBF4P-00ECj4-4y; Thu, 07 Dec 2023 15:09:41 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1rBF4O-00FvTQ-SE; Thu, 07 Dec 2023 15:09:40 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 2/4] hwmon: (smsc47m1) Convert to platform remove callback returning void Date: Thu, 7 Dec 2023 15:09:30 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1724; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=djNuGlZBa8KuhXd2nwqiTYqdNvlNsHrtELvh/lWrW2I=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlcdIa2wv9O1GGlupOEIuyQ2W0XJHlhu86XgRES 4OF8sovhaKJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZXHSGgAKCRCPgPtYfRL+ TqgRB/9KmTd6erOBDe2QNskPpIyCoh3aAir3MDcq7Jl7DLaxuKL5DuuLqu10Lj1sur2izz6BuXa DUuy9Rq5yN3ITYQss+G9FW2S+hnD+/4X8zH093L8DHWoT28ocEy0mMbir1s2IPYOKzqLy/K8K5u j+oQBmRcWMl5azGFXsicdIgOSG//TtcyjhSqdBWBZkUbW6wfA82bt+p4tXADoYd9gNnInjmPfu7 2hnsIZAou6L+qK2L0PeG2Fw6HrQNQEk3gExA3HMv76uI+3Agaxco3f56JdTDq3ITHs4ACbOtJ9L rtS/o+ammOYCLD4Vr7hFL7QkZISGoU3OaTf2d1Dkud7oGK1J X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-hwmon@vger.kernel.org The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König --- drivers/hwmon/smsc47m1.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 29ea8fb4f353..bda39a5a5d4c 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -840,14 +840,12 @@ static int __init smsc47m1_probe(struct platform_device *pdev) return err; } -static int __exit smsc47m1_remove(struct platform_device *pdev) +static void __exit smsc47m1_remove(struct platform_device *pdev) { struct smsc47m1_data *data = platform_get_drvdata(pdev); hwmon_device_unregister(data->hwmon_dev); smsc47m1_remove_files(&pdev->dev); - - return 0; } /* @@ -860,7 +858,7 @@ static struct platform_driver smsc47m1_driver __refdata = { .driver = { .name = DRVNAME, }, - .remove = __exit_p(smsc47m1_remove), + .remove_new = __exit_p(smsc47m1_remove), }; static int __init smsc47m1_device_add(unsigned short address, From patchwork Thu Dec 7 14:09:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13483337 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49E0010E9 for ; Thu, 7 Dec 2023 06:09:49 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rBF4P-0001a1-Nc; Thu, 07 Dec 2023 15:09:41 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBF4P-00ECj7-Az; Thu, 07 Dec 2023 15:09:41 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1rBF4P-00FvTU-1n; Thu, 07 Dec 2023 15:09:41 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 3/4] hwmon: (smsc47m1) Simplify device registration Date: Thu, 7 Dec 2023 15:09:31 +0100 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2064; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=1UHithayHvrvd7Y8YvIbl2aB8yeC7z+o8wjKg1bl26I=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlcdIbmdgDTdzl6Qje5Ezo0bxdCv39v47In1/Je h8bbQAu3gOJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZXHSGwAKCRCPgPtYfRL+ TtAjCACNvrwdClOdLlDi1KF9X5d6XvERExUbjyIX6/UTOV0YzK1bR9+vIEkY0I3kN43AyTf3tsf 7mak/Esz5NNG1IFUc9qlrZQmsAQARv7BXHomsxHZ12Fy1xEedK7k/PwpDyvgQTsM92e1GYcIjZF AO0ejZ6C1UdmGQ/oEh1f03kFIqZlxsu2ziBVSAj7Jbb95Dy0mEXKowW0fglMvlOIJWRszZdvbNf PE9TuNFg8voXmeh502pLsSNBpg1qkF85k2VgCRtQ64H/E//eh6hQg7bkKmfi4cFSAWQ2iydGf1c Y73XlhvUeBxbc/V4IFm7iTo01KjsYhCe0d/VBG6rcau1TO5z X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-hwmon@vger.kernel.org Use platform_device_register_full() instead of open coding this function. Signed-off-by: Uwe Kleine-König --- drivers/hwmon/smsc47m1.c | 44 +++++++++++++--------------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index bda39a5a5d4c..7e9c183b8e7f 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -864,50 +864,34 @@ static struct platform_driver smsc47m1_driver __refdata = { static int __init smsc47m1_device_add(unsigned short address, const struct smsc47m1_sio_data *sio_data) { - struct resource res = { + const struct resource res = { .start = address, .end = address + SMSC_EXTENT - 1, .name = DRVNAME, .flags = IORESOURCE_IO, }; + const struct platform_device_info pdevinfo = { + .name = DRVNAME, + .id = address, + .res = &res, + .num_res = 1, + .data = sio_data, + .size_data = sizeof(struct smsc47m1_sio_data), + }; int err; err = smsc47m1_handle_resources(address, sio_data->type, CHECK, NULL); if (err) - goto exit; + return err; - pdev = platform_device_alloc(DRVNAME, address); - if (!pdev) { - err = -ENOMEM; + + pdev = platform_device_register_full(&pdevinfo); + if (IS_ERR(pdev)) { pr_err("Device allocation failed\n"); - goto exit; - } - - err = platform_device_add_resources(pdev, &res, 1); - if (err) { - pr_err("Device resource addition failed (%d)\n", err); - goto exit_device_put; - } - - err = platform_device_add_data(pdev, sio_data, - sizeof(struct smsc47m1_sio_data)); - if (err) { - pr_err("Platform data allocation failed\n"); - goto exit_device_put; - } - - err = platform_device_add(pdev); - if (err) { - pr_err("Device addition failed (%d)\n", err); - goto exit_device_put; + return PTR_ERR(pdev); } return 0; - -exit_device_put: - platform_device_put(pdev); -exit: - return err; } static int __init sm_smsc47m1_init(void) From patchwork Thu Dec 7 14:09:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13483336 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5E7510E4 for ; Thu, 7 Dec 2023 06:09:43 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rBF4P-0001aP-Vl; Thu, 07 Dec 2023 15:09:41 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBF4P-00ECjA-IQ; Thu, 07 Dec 2023 15:09:41 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1rBF4P-00FvTY-9P; Thu, 07 Dec 2023 15:09:41 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 4/4] hwmon: (smsc47m1) Rename global platform device variable Date: Thu, 7 Dec 2023 15:09:32 +0100 Message-ID: <68a959b56da7f9452557d08c72249182364b0dd0.1701957841.git.u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2133; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=2hw4xctJ9dtpVr/uqyBD2QvFtjr8gWiF7+W40DtjipI=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBlcdIcTtfcsci/kXRRVyrrCW05IWgrNZ+kuoKzh NzOwcPHHTGJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZXHSHAAKCRCPgPtYfRL+ TlwrB/0cVzsAGfE5PH80sdQRFIPy1rp977tbsANDDCtRppOc/rBlwuf/jn/0WC68wVdo2/nnXUI DnYsiu2RDtS7yjr8n6x/tNISOHlYvdsmxim4kpThfy1yUS4+PKiQOpfbz+GzfjiHIMgjLaMuPVp rfZZNi7c+w81pFO8Fwvc57StA4l/ERXcC/O6O46Wb/HUJGPN6Wb2x8ETf1d+HfahUesxPyP+j0M DiMHNh+FNBNeQ+aqjBAI6ov27IPLhrTsZdKJFy0Aov9wT/If/R23puuBl9Jvhiy0mvBez4AY6uW w3nz2JTBSncg4W75R1u71bJTMtnsIFoN2rHXYr8/KSzyMpEm X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-hwmon@vger.kernel.org pdev is a bad name for a global variable. Still more as the driver has functions where pdev is a local variable. Rename it to smsc47m1_pdev. Signed-off-by: Uwe Kleine-König --- drivers/hwmon/smsc47m1.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 7e9c183b8e7f..ad52839e4f31 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -33,7 +33,7 @@ static unsigned short force_id; module_param(force_id, ushort, 0); MODULE_PARM_DESC(force_id, "Override the detected device ID"); -static struct platform_device *pdev; +static struct platform_device *smsc47m1_pdev; #define DRVNAME "smsc47m1" enum chips { smsc47m1, smsc47m2 }; @@ -885,10 +885,10 @@ static int __init smsc47m1_device_add(unsigned short address, return err; - pdev = platform_device_register_full(&pdevinfo); - if (IS_ERR(pdev)) { + smsc47m1_pdev = platform_device_register_full(&pdevinfo); + if (IS_ERR(smsc47m1_pdev)) { pr_err("Device allocation failed\n"); - return PTR_ERR(pdev); + return PTR_ERR(smsc47m1_pdev); } return 0; @@ -905,7 +905,7 @@ static int __init sm_smsc47m1_init(void) return err; address = err; - /* Sets global pdev as a side effect */ + /* Sets global smsc47m1_pdev as a side effect */ err = smsc47m1_device_add(address, &sio_data); if (err) return err; @@ -917,7 +917,7 @@ static int __init sm_smsc47m1_init(void) return 0; exit_device: - platform_device_unregister(pdev); + platform_device_unregister(smsc47m1_pdev); smsc47m1_restore(&sio_data); return err; } @@ -925,8 +925,8 @@ static int __init sm_smsc47m1_init(void) static void __exit sm_smsc47m1_exit(void) { platform_driver_unregister(&smsc47m1_driver); - smsc47m1_restore(dev_get_platdata(&pdev->dev)); - platform_device_unregister(pdev); + smsc47m1_restore(dev_get_platdata(&smsc47m1_pdev->dev)); + platform_device_unregister(smsc47m1_pdev); } MODULE_AUTHOR("Mark D. Studebaker ");