Skip to contentSkip to conversation

kpartx/devmapper.c: fix unused-but-set variable error

PATCH In review Sergei Trofimovich 2 participants 7 messages Jan 5, 2022 – Jan 10, 2022 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kpartx/devmapper.c: fix unused-but-set variable error

On gcc-12 build failed as:

devmapper.c: In function 'dm_simplecmd':
devmapper.c:61:13: error: unused variable 'udev_wait_flag' [-Werror=unused-variable]
61 | int udev_wait_flag = (task == DM_DEVICE_RESUME ||
| ^~~~~~~~~~~~~~

Fix error by hiding it's declaration under #ifdef that uses it.
CC: Martin Wilck <[email protected]>
CC: Benjamin Marzinski <[email protected]>

---
 kpartx/devmapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kpartx/devmapper.c +1 -1
index 3efd6dfc..511c090f 100644
@@ -58,9 +58,9 @@ out:
 int dm_simplecmd(int task, const char *name, int no_flush, uint16_t udev_flags)
 {
 	int r = 0;
+#ifdef LIBDM_API_COOKIE
 	int udev_wait_flag = (task == DM_DEVICE_RESUME ||
 			      task == DM_DEVICE_REMOVE);
-#ifdef LIBDM_API_COOKIE
 	uint32_t cookie = 0;
 #endif
 	struct dm_task *dmt;
Signature · 6 lines
2.34.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw
Quoted 8 lines · Sergei Trofimovich

On gcc-12 build failed as:

    devmapper.c: In function 'dm_simplecmd':
    devmapper.c:61:13: error: unused variable 'udev_wait_flag' [- Werror=unused-variable]
       61 |         int udev_wait_flag = (task == DM_DEVICE_RESUME || |             ^~~~~~~~~~~~~~

Quoted 6 lines

Fix error by hiding it's declaration under #ifdef that uses it.
CC: Martin Wilck <[email protected]>
CC: Benjamin Marzinski <[email protected]>
---
 kpartx/devmapper.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

Under https://github.com/opensvc/multipath-tools/pull/23/files
you posted a different patch, containing additional changes.

Are you saying this alone fixes your issue?

Martin

Quoted 9 lines
kpartx/devmapper.c +0 -0
index 3efd6dfc..511c090f 100644
@@ -58,9 +58,9 @@ out:

 int dm_simplecmd(int task, const char *name, int no_flush, uint16_t udev_flags)
 {

Quoted 8 lines

        int r = 0;
+#ifdef LIBDM_API_COOKIE
        int udev_wait_flag = (task == DM_DEVICE_RESUME || task == DM_DEVICE_REMOVE); -#ifdef LIBDM_API_COOKIE
        uint32_t cookie = 0;
 #endif
        struct dm_task *dmt;

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#2 lore raw
Quoted 17 lines · Martin Wilck
Quoted 9 lines · Sergei Trofimovich

On gcc-12 build failed as:

    devmapper.c: In function 'dm_simplecmd':
    devmapper.c:61:13: error: unused variable 'udev_wait_flag' [- Werror=unused-variable]
       61 |         int udev_wait_flag = (task == DM_DEVICE_RESUME

||
          |             ^~~~~~~~~~~~~~
Quoted 6 lines

Fix error by hiding it's declaration under #ifdef that uses it.
CC: Martin Wilck <[email protected]>
CC: Benjamin Marzinski <[email protected]>
---
 kpartx/devmapper.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines

Under https://github.com/opensvc/multipath-tools/pull/23/files
you posted a different patch, containing additional changes.

Are you saying this alone fixes your issue?

Sorry, I overlooked your second patch.
Next time, please send a series.

Regards
Martin

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#6 lore raw
In reply to Sergei Trofimovich
Quoted 11 lines · Sergei Trofimovich

On gcc-12 build failed as:

    devmapper.c: In function 'dm_simplecmd':
    devmapper.c:61:13: error: unused variable 'udev_wait_flag' [- Werror=unused-variable]
       61 |         int udev_wait_flag = (task == DM_DEVICE_RESUME || |             ^~~~~~~~~~~~~~

Fix error by hiding it's declaration under #ifdef that uses it.
CC: Martin Wilck <[email protected]>
CC: Benjamin Marzinski <[email protected]>

Please add a Signed-off-by: line. Same for the other patch. Apart from that, both patches are ok.

Martin

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#3 lore raw

PATCH v2 1/2 kpartx/devmapper.c: fix unused-but-set variable error

In reply to Martin Wilck

On gcc-12 build failed as:

devmapper.c: In function 'dm_simplecmd':
devmapper.c:61:13: error: unused variable 'udev_wait_flag' [-Werror=unused-variable]
61 | int udev_wait_flag = (task == DM_DEVICE_RESUME ||
| ^~~~~~~~~~~~~~

Fix error by hiding it's declaration under #ifdef that uses it.

CC Martin Wilck <[email protected]>
CC Benjamin Marzinski <[email protected]>
---
 kpartx/devmapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kpartx/devmapper.c +1 -1
index 3efd6dfc..511c090f 100644
@@ -58,9 +58,9 @@ out:
 int dm_simplecmd(int task, const char *name, int no_flush, uint16_t udev_flags)
 {
 	int r = 0;
+#ifdef LIBDM_API_COOKIE
 	int udev_wait_flag = (task == DM_DEVICE_RESUME ||
 			      task == DM_DEVICE_REMOVE);
-#ifdef LIBDM_API_COOKIE
 	uint32_t cookie = 0;
 #endif
 	struct dm_task *dmt;
Signature · 6 lines
2.34.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#4 lore raw

PATCH v2 2/2 kpartx/devmapper.c: fix unused variable error

Without the change the build fails as:

devmapper.c:58:69: error: unused parameter 'udev_flags' [-Werror=unused-parameter]
58 | int dm_simplecmd(int task, const char *name, int no_flush, uint16_t udev_flags)
| ~~~~~~~~~^~~~~~~~~~

The change adds __attribute__((used)) annotation to unused function parameter.

CC Martin Wilck <[email protected]>
CC Benjamin Marzinski <[email protected]>
---
 kpartx/devmapper.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
kpartx/devmapper.c +7 -1
index 511c090f..49ffd310 100644
@@ -18,6 +18,12 @@
 #define MAX_PREFIX_LEN (_UUID_PREFIX_LEN + 4)
 #define PARAMS_SIZE 1024
 
+#ifdef LIBDM_API_COOKIE
+#    define __DM_API_COOKIE_UNUSED__ /* empty */
+#else
+#    define __DM_API_COOKIE_UNUSED__ __attribute__((unused))
+#endif
+
 int dm_prereq(char * str, uint32_t x, uint32_t y, uint32_t z)
 {
 	int r = 1;
@@ -55,7 +61,7 @@ out:
 	return r;
 }
 
-int dm_simplecmd(int task, const char *name, int no_flush, uint16_t udev_flags)
+int dm_simplecmd(int task, const char *name, int no_flush, __DM_API_COOKIE_UNUSED__ uint16_t udev_flags)
 {
 	int r = 0;
 #ifdef LIBDM_API_COOKIE
Signature · 6 lines
2.34.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v2 1/2
#5 lore raw
In reply to Sergei Trofimovich
Quoted 8 lines · Sergei Trofimovich

On gcc-12 build failed as:

    devmapper.c: In function 'dm_simplecmd':
    devmapper.c:61:13: error: unused variable 'udev_wait_flag' [- Werror=unused-variable]
       61 |         int udev_wait_flag = (task == DM_DEVICE_RESUME || |             ^~~~~~~~~~~~~~

Quoted 5 lines

Fix error by hiding it's declaration under #ifdef that uses it.

CC Martin Wilck <[email protected]>
CC Benjamin Marzinski <[email protected]>

For this series:

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel