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);