From patchwork Sun Mar 26 14:30:27 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: 13188207 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [85.220.165.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8A703C13 for ; Sun, 26 Mar 2023 14:32:43 +0000 (UTC) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgRQ3-0007ki-TF; Sun, 26 Mar 2023 16:32:27 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pgRQ2-006rYk-FQ; Sun, 26 Mar 2023 16:32:26 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pgRQ1-0088To-Gz; Sun, 26 Mar 2023 16:32:25 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Hans Verkuil , Mauro Carvalho Chehab , Benson Leung , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Ajye Huang , Rory Liu , Scott Chao Cc: Guenter Roeck , linux-media@vger.kernel.org, chrome-platform@lists.linux.dev, kernel@pengutronix.de Subject: [PATCH 001/117] media: cros-ec-cec: Don't exit early in .remove() callback Date: Sun, 26 Mar 2023 16:30:27 +0200 Message-Id: <20230326143224.572654-3-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326143224.572654-1-u.kleine-koenig@pengutronix.de> References: <20230326143224.572654-1-u.kleine-koenig@pengutronix.de> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1594; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=kgeU/STcVheBqmh2v51qr6VZsSNJVCPY6dohJcgJw24=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBkIFZ2Jv2IUB+TsS3cRYmo+391OUWzOKdO517oT nXTmcDYqVmJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZCBWdgAKCRCPgPtYfRL+ TjYWB/4m5JSP0Y/kyyvfcxLCp2Mx83+WLdRIAw61A98JK4h3GGMaoyVakeu38HDZ+gHXnttUWMb q2H1Q4VgCoQb01IouSdyomqPVry9laERYjUAjoCvfCsiJ3SUaUvrG7XPn1sFykGj1YiqKYTrUA7 9R+r7LxcK5q+d1Zgu7JUdjnkYGvd8I6syqeFsjGrxAqbfUVTaXPP3itY7WU8Tr3vQ0mnUXI95Bm VT33iKQS/ZI4RQF4az4eJJPU2y/WiRReM6sizGx+Ru8SdPYFRBZeAuOEyTZOAjqecMeACJUQmoW Ab+PZ0TiqEUghhEwXOdcx1Mg3yn7cYV/3jYiXScoLocPg+ae 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.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: chrome-platform@lists.linux.dev Exiting early in remove without releasing all acquired resources yields leaks. Note that e.g. memory allocated with devm_zalloc() is freed after .remove() returns, even if the return code was negative. While blocking_notifier_chain_unregister() won't fail and so the change is somewhat cosmetic, platform driver's .remove callbacks are about to be converted to return void. To prepare that, keep the error message but don't return early. Signed-off-by: Uwe Kleine-König --- drivers/media/cec/platform/cros-ec/cros-ec-cec.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 6ebedc71d67d..960432230bbf 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -332,14 +332,16 @@ static int cros_ec_cec_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; + /* + * blocking_notifier_chain_unregister() only fails if the notifier isn't + * in the list. We know it was added to it by .probe(), so there should + * be no need for error checking. Be cautious and still check. + */ ret = blocking_notifier_chain_unregister( &cros_ec_cec->cros_ec->event_notifier, &cros_ec_cec->notifier); - - if (ret) { + if (ret) dev_err(dev, "failed to unregister notifier\n"); - return ret; - } cec_notifier_cec_adap_unregister(cros_ec_cec->notify, cros_ec_cec->adap); From patchwork Sun Mar 26 14:30: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: 13188205 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [85.220.165.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAA1162E for ; Sun, 26 Mar 2023 14:32:41 +0000 (UTC) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgRQ4-0007lJ-NI; Sun, 26 Mar 2023 16:32:28 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pgRQ4-006rZ8-1O; Sun, 26 Mar 2023 16:32:28 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pgRQ1-0088Tu-Vm; Sun, 26 Mar 2023 16:32:25 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Hans Verkuil , Mauro Carvalho Chehab , Benson Leung , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Ajye Huang , Scott Chao , Rory Liu Cc: Guenter Roeck , linux-media@vger.kernel.org, chrome-platform@lists.linux.dev, kernel@pengutronix.de Subject: [PATCH 002/117] media: cros-ec-cec: Don't exit early in .remove() callback Date: Sun, 26 Mar 2023 16:30:29 +0200 Message-Id: <20230326143224.572654-5-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326143224.572654-1-u.kleine-koenig@pengutronix.de> References: <20230326143224.572654-1-u.kleine-koenig@pengutronix.de> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1594; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=kgeU/STcVheBqmh2v51qr6VZsSNJVCPY6dohJcgJw24=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBkIFZ4Jv2IUB+TsS3cRYmo+391OUWzOKdO517oT nXTmcDYqVmJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZCBWeAAKCRCPgPtYfRL+ Tn0nCACG3nHmXDsIm/agxXT0CZNZytZ+mB4wXjRqCDzfvWr9rUFyDnzKCf0bxLKSCViCk3nPcu/ 6/PQElbeTxe3RbxFfXSGo0ahlP2PcwJyHlJD8hyR+D9Ziab15xZCFkLihGxrCxokGkmBsaF3sp4 Puz4f1E7WP0LPLD1qKp8t4dY1/Gt08WAzm31yzVvYq+q/DktMX4XHvejS+i5WmzwBhrF4/lnZdI 2lMaOhQB709qHf792KJgszacE+2T0KoDPGt2MYkqn9zF4jBt0yXf26C1cWklMZ+6diUaS0Y/quF sXjILaYKhadjnN6d0Pe9z7Flk4i8Yg4MsbN2yT0VhBxqBfL8 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.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: chrome-platform@lists.linux.dev Exiting early in remove without releasing all acquired resources yields leaks. Note that e.g. memory allocated with devm_zalloc() is freed after .remove() returns, even if the return code was negative. While blocking_notifier_chain_unregister() won't fail and so the change is somewhat cosmetic, platform driver's .remove callbacks are about to be converted to return void. To prepare that, keep the error message but don't return early. Signed-off-by: Uwe Kleine-König Reviewed-by: Guenter Roeck --- drivers/media/cec/platform/cros-ec/cros-ec-cec.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 6ebedc71d67d..960432230bbf 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -332,14 +332,16 @@ static int cros_ec_cec_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; + /* + * blocking_notifier_chain_unregister() only fails if the notifier isn't + * in the list. We know it was added to it by .probe(), so there should + * be no need for error checking. Be cautious and still check. + */ ret = blocking_notifier_chain_unregister( &cros_ec_cec->cros_ec->event_notifier, &cros_ec_cec->notifier); - - if (ret) { + if (ret) dev_err(dev, "failed to unregister notifier\n"); - return ret; - } cec_notifier_cec_adap_unregister(cros_ec_cec->notify, cros_ec_cec->adap); From patchwork Sun Mar 26 14:30: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: 13188206 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [85.220.165.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1031933DA for ; Sun, 26 Mar 2023 14:32:42 +0000 (UTC) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgRQ3-0007kj-TF; Sun, 26 Mar 2023 16:32:27 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pgRQ3-006rYp-3e; Sun, 26 Mar 2023 16:32:27 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pgRQ2-0088Ty-6C; Sun, 26 Mar 2023 16:32:26 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Hans Verkuil , Mauro Carvalho Chehab , Benson Leung , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Scott Chao , Rory Liu , Ajye Huang Cc: Guenter Roeck , linux-media@vger.kernel.org, chrome-platform@lists.linux.dev, kernel@pengutronix.de Subject: [PATCH 003/117] media: cros-ec-cec: Convert to platform remove callback returning void Date: Sun, 26 Mar 2023 16:30:30 +0200 Message-Id: <20230326143224.572654-6-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326143224.572654-1-u.kleine-koenig@pengutronix.de> References: <20230326143224.572654-1-u.kleine-koenig@pengutronix.de> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1824; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=7R9wKQxWA44fiXMEYARiwDyElWOf/YQkKOdlXBlMzbk=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBkIFZ58QDpXlzM0zNEkr6TWGtNeAotmE8ENdA8i +nW33qtuOqJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZCBWeQAKCRCPgPtYfRL+ TppCB/93wZB5ZjDqzIYqffIxt9i6KyyUwipLcXNpswTw47lIhAn5FcKeus4st6tmtZ9gC57A0PS YBGYErj+uD/ZpXkqx+WV8d6Kg8ZdVtdHQT2UJ0oWq7sYZQ5sLUkMiTZpjMTExnDnDQm6UAAdKg2 lsgaq8WvIB1Yx673JBmi/3wfpiOgj6+QafjuBatj9RAIBua1ZEvwp283bA148WxMLjXQKN3n2wA q9iTk9wW6eprs/tlMK9uaLI7sv/IvzqWOueE2Oi2EKEIYzCA8iTG67jNlMMOCOb9WB7ywTIDqO1 x05Bd/N2YZ6DxAgWKoCkhP9CtAHzyI7U270VeZaO15g1WaO1 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.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: chrome-platform@lists.linux.dev 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 (mostly) ignored 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. Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König Reviewed-by: Guenter Roeck --- drivers/media/cec/platform/cros-ec/cros-ec-cec.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c index 960432230bbf..3d2600af9fc1 100644 --- a/drivers/media/cec/platform/cros-ec/cros-ec-cec.c +++ b/drivers/media/cec/platform/cros-ec/cros-ec-cec.c @@ -326,7 +326,7 @@ static int cros_ec_cec_probe(struct platform_device *pdev) return ret; } -static int cros_ec_cec_remove(struct platform_device *pdev) +static void cros_ec_cec_remove(struct platform_device *pdev) { struct cros_ec_cec *cros_ec_cec = platform_get_drvdata(pdev); struct device *dev = &pdev->dev; @@ -346,13 +346,11 @@ static int cros_ec_cec_remove(struct platform_device *pdev) cec_notifier_cec_adap_unregister(cros_ec_cec->notify, cros_ec_cec->adap); cec_unregister_adapter(cros_ec_cec->adap); - - return 0; } static struct platform_driver cros_ec_cec_driver = { .probe = cros_ec_cec_probe, - .remove = cros_ec_cec_remove, + .remove_new = cros_ec_cec_remove, .driver = { .name = DRV_NAME, .pm = &cros_ec_cec_pm_ops,