Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Lu Hongfei <luhongfei@vivo.com>,
	kernel-janitors@vger.kernel.org,
	linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org, opensource.kernel@vivo.com,
	Angelo Gioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Moudy Ho <moudy.ho@mediatek.com>, Sun Ke <sunke32@huawei.com>
Cc: LKML <linux-kernel@vger.kernel.org>, cocci@inria.fr
Subject: Re: [cocci] [PATCH] media: platform: mtk-mdp3: Fix resource leaks in mdp_get_subsys_id()?
Date: Mon, 12 Jun 2023 18:02:27 +0200	[thread overview]
Message-ID: <fbbb84c3-f3a9-1761-e5c0-227fcfce0a63@web.de> (raw)
In-Reply-To: <20230530101724.31412-1-luhongfei@vivo.com>

I would find an other patch subject more appropriate.


> Use put_device to release the object get through of_find_device_by_node,
> avoiding resource leaks.

How do you think about a wording variant for the change description
like the following?

* Add a put_device() call for the release of the object
  which was determined by a of_find_device_by_node() call.

* Use an additional label.

* Increase the usage of the variable “ret”.


> +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> @@ -892,11 +892,13 @@ static int mdp_get_subsys_id(struct mdp_dev *mdp, struct device *dev,
>  	ret = cmdq_dev_get_client_reg(&comp_pdev->dev, &cmdq_reg, index);
>  	if (ret != 0) {
>  		dev_err(&comp_pdev->dev, "cmdq_dev_get_subsys fail!\n");
> +		put_device(&comp_pdev->dev);
>  		return -EINVAL;
>  	}
>
>  	comp->subsys_id = cmdq_reg.subsys;
>  	dev_dbg(&comp_pdev->dev, "subsys id=%d\n", cmdq_reg.subsys);
> +	put_device(&comp_pdev->dev);
>
>  	return 0;
>  }

How will the chances evolve to integrate the following change variant?

 	ret = cmdq_dev_get_client_reg(&comp_pdev->dev, &cmdq_reg, index);
 	if (ret != 0) {
 		dev_err(&comp_pdev->dev, "cmdq_dev_get_subsys fail!\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto put_device;
 	}

 	comp->subsys_id = cmdq_reg.subsys;
 	dev_dbg(&comp_pdev->dev, "subsys id=%d\n", cmdq_reg.subsys);
+put_device:
+	put_device(&comp_pdev->dev);
-
-	return 0;
+	return ret;
 }


Regards,
Markus

           reply	other threads:[~2023-06-12 16:03 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20230530101724.31412-1-luhongfei@vivo.com>]

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=fbbb84c3-f3a9-1761-e5c0-227fcfce0a63@web.de \
    --to=markus.elfring@web.de \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=arnd@arndb.de \
    --cc=cocci@inria.fr \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=luhongfei@vivo.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=moudy.ho@mediatek.com \
    --cc=opensource.kernel@vivo.com \
    --cc=sunke32@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).