lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221224115657.kqyocti356cwm7hc@pengutronix.de>
Date:   Sat, 24 Dec 2022 12:56:57 +0100
From:   Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To:     Julia Lawall <Julia.Lawall@...ia.fr>,
        Nicolas Palix <nicolas.palix@...g.fr>
Cc:     cocci@...ia.fr, linux-kernel@...r.kernel.org, kernel@...gutronix.de
Subject: coccinelle: How to remove a return at the end of a void function?

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:

-------->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/ |

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ