From: Julia Lawall <julia.lawall@inria.fr>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Julia Lawall <Julia.Lawall@inria.fr>,
Nicolas Palix <nicolas.palix@imag.fr>,
cocci@inria.fr, linux-kernel@vger.kernel.org,
kernel@pengutronix.de
Subject: Re: [cocci] coccinelle: How to remove a return at the end of a void function?
Date: Sat, 24 Dec 2022 13:28:04 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.22.394.2212241326310.2711@hadrien> (raw)
In-Reply-To: <20221224115657.kqyocti356cwm7hc@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 3337 bytes --]
On Sat, 24 Dec 2022, Uwe Kleine-König wrote:
> Hello,
>
> I work on a patch set that eventually makes the function
> rtsx_usb_sdmmc_drv_remove() return void:
>
> A simplified spatch looks as follows:
>
> -------->8--------
> virtual patch
>
> @p1@
> identifier pdev;
> @@
> -int
> +void
> rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev) {
> <...
> -return 0;
> +return;
> ...>
> }
> -------->8--------
>
> This results in:
>
> -------->8--------
> diff -u -p a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
> --- a/drivers/mmc/host/rtsx_usb_sdmmc.c
> +++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
> @@ -1379,13 +1379,13 @@ static int rtsx_usb_sdmmc_drv_probe(stru
> return 0;
> }
>
> -static int rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev)
> +static void rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev)
> {
> struct rtsx_usb_sdmmc *host = platform_get_drvdata(pdev);
> struct mmc_host *mmc;
>
> if (!host)
> - return 0;
> + return;
>
> mmc = host->mmc;
> host->host_removal = true;
> @@ -1416,7 +1416,7 @@ static int rtsx_usb_sdmmc_drv_remove(str
> dev_dbg(&(pdev->dev),
> ": Realtek USB SD/MMC module has been removed\n");
>
> - return 0;
> + return;
> }
>
> #ifdef CONFIG_PM
> -------->8--------
>
> which is as intended. Now I want to remove the useless "return;" at the
> end of the function, however adding
>
> -------->8--------
> @p2 depends on p1@
> identifier pdev;
> @@
> void rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev) {
> ...
> -return;
> }
> -------->8--------
>
> to the spatch doesn't (only) do the intended:
The problem is that Coccinelle is following the control-flow through the
function, and all of the returns are at the end of a control.flow path.
The simple, hacky solution is to change the return;s into some function
call Return();, then do like the above for Return(); and then change the
Return();s back to return;s
julia
>
> -------->8--------
> diff -u -p a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
> --- a/drivers/mmc/host/rtsx_usb_sdmmc.c
> +++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
> @@ -1379,13 +1379,13 @@ static int rtsx_usb_sdmmc_drv_probe(stru
> return 0;
> }
>
> -static int rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev)
> +static void rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev)
> {
> struct rtsx_usb_sdmmc *host = platform_get_drvdata(pdev);
> struct mmc_host *mmc;
>
> if (!host)
> - return 0;
> + {}
>
> mmc = host->mmc;
> host->host_removal = true;
> @@ -1415,8 +1415,6 @@ static int rtsx_usb_sdmmc_drv_remove(str
>
> dev_dbg(&(pdev->dev),
> ": Realtek USB SD/MMC module has been removed\n");
> -
> - return 0;
> }
>
> #ifdef CONFIG_PM
> -------->8--------
>
> It's obvious to me, why coccinelle also removes the first return, but
> it's not obvious to me, how to prevent this and only drop the 2nd one.
>
> Do you have a hint for me?
>
> Thanks in advance and happy holidays,
> Uwe
>
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
>
next prev parent reply other threads:[~2022-12-24 12:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-24 11:56 [cocci] coccinelle: How to remove a return at the end of a void function? Uwe Kleine-König
2022-12-24 12:28 ` Julia Lawall [this message]
2022-12-25 21:20 ` Uwe Kleine-König
2022-12-26 16:02 ` Julia Lawall
2022-12-27 9:55 ` Uwe Kleine-König
2022-12-27 11:26 ` Julia Lawall
2022-12-27 11:54 ` Uwe Kleine-König
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=alpine.DEB.2.22.394.2212241326310.2711@hadrien \
--to=julia.lawall@inria.fr \
--cc=cocci@inria.fr \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.palix@imag.fr \
--cc=u.kleine-koenig@pengutronix.de \
/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 NNTP newsgroup(s).