vfio/container: Replace basename with g_path_get_basename
PATCH 1/1 vfio/container: Replace basename with g_path_get_basename
g_path_get_basename() is a portable utility function that has the advantage of not modifing the string argument. It also fixes a compile breakage with the Musl C library reported in [1].
[1] https://lore.kernel.org/all/[email protected]/
--- hw/vfio/container.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/container.c +3 -2
@@ -869,7 +869,8 @@ static void vfio_put_base_device(VFIODevice *vbasedev)static int vfio_device_groupid (VFIODevice *vbasedev,Error **errp) { -char *tmp, group_path[PATH_MAX ], *group_name; +char *tmp, group_path[PATH_MAX ]; + g_autofree char *group_name = NULL;int ret, groupid;ssize_t len;
@@ -885,7 +886,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) group_path[len] =0 ; - group_name =basename (group_path); + group_name =g_path_get_basename (group_path);if (sscanf (group_name,"%d" , &groupid) !=1 ) {error_setg_errno (errp, errno,"failed to read %s" , group_path);return -errno;
Signature · 1 line
2.43.0
Hi Cédric,
Quoted 8 lines · Cédric Le Goater
g_path_get_basename()is a portable utility function that has the advantage of not modifing the string argument. It also fixes a compile breakage with the Musl C library reported in [1].[1] https://lore.kernel.org/all/[email protected]/
Reported-by Khem Raj <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Eric
Quoted 27 lines
--- hw/vfio/container.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/vfio/container.c +3
-2@@ -869,7 +869,8 @@ static void vfio_put_base_device(VFIODevice *vbasedev)static int vfio_device_groupid (VFIODevice *vbasedev,Error **errp) { -char *tmp, group_path[PATH_MAX ], *group_name; +char *tmp, group_path[PATH_MAX ]; + g_autofree char *group_name = NULL;int ret, groupid;ssize_t len;@@ -885,7 +886,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) group_path[len] =0 ; - group_name =basename (group_path); + group_name =g_path_get_basename (group_path);if (sscanf (group_name,"%d" , &groupid) !=1 ) {error_setg_errno (errp, errno,"failed to read %s" , group_path);return -errno;
Hi Cédric,
Quoted 9 lines · Cédric Le Goater
Date: Wed, 20 Dec 2023 14:53:02 +0100
From: Cédric Le Goater <[email protected]>
Subject: [PATCH] vfio/container: Replace basename withg_path_get_basename
X-Mailer: git-send-email 2.43.0
g_path_get_basename()is a portable utility function that has the advantage of not modifing the string argument. It also fixes a compile breakage with the Musl C library reported in [1].
Quoted 5 lines
[1] https://lore.kernel.org/all/[email protected]/
Reported-by Khem Raj <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Just one additional question, I understand that QEMU should replace all basename() with g_path_get_basename(), right?
I find hw/s390x/s390-ccw.c also uses basename(). Maybe I can clean it up to avoid potentially similar issue.
Thanks,
Zhao
Quoted 30 lines
hw/vfio/container.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/vfio/container.c +3
-2@@ -869,7 +869,8 @@ static void vfio_put_base_device(VFIODevice *vbasedev)static int vfio_device_groupid (VFIODevice *vbasedev,Error **errp) { -char *tmp, group_path[PATH_MAX ], *group_name; +char *tmp, group_path[PATH_MAX ]; + g_autofree char *group_name = NULL;int ret, groupid;ssize_t len;@@ -885,7 +886,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) group_path[len] =0 ; - group_name =basename (group_path); + group_name =g_path_get_basename (group_path);if (sscanf (group_name,"%d" , &groupid) !=1 ) {error_setg_errno (errp, errno,"failed to read %s" , group_path);return -errno;Signature · 1 line
2.43.0
Hello,
Quoted 18 lines · Zhao Liu
Hi Cédric,
Quoted 9 lines · Cédric Le Goater
Date: Wed, 20 Dec 2023 14:53:02 +0100
From: Cédric Le Goater <[email protected]>
Subject: [PATCH] vfio/container: Replace basename withg_path_get_basename
X-Mailer: git-send-email 2.43.0
g_path_get_basename()is a portable utility function that has the advantage of not modifing the string argument. It also fixes a compile breakage with the Musl C library reported in [1].Quoted 5 lines
[1] https://lore.kernel.org/all/[email protected]/
Reported-by Khem Raj <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 7 lines
Reviewed-by Zhao Liu <[email protected]>Just one additional question, I understand that QEMU should replace all
basename()withg_path_get_basename(), right?I find
hw/s390x/s390-ccw.calso usesbasename(). Maybe I can clean it up to avoid potentially similar issue.
I guess so and I wonder why 3e015d815b3f didn't do the change. Anyhow, please cc me, I can give it a try.
Thanks,
C.
Quoted 35 lines
Thanks,
ZhaoQuoted 30 lines
hw/vfio/container.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/vfio/container.c +3
-2@@ -869,7 +869,8 @@ static void vfio_put_base_device(VFIODevice *vbasedev)static int vfio_device_groupid (VFIODevice *vbasedev,Error **errp) { -char *tmp, group_path[PATH_MAX ], *group_name; +char *tmp, group_path[PATH_MAX ]; + g_autofree char *group_name = NULL;int ret, groupid;ssize_t len;@@ -885,7 +886,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) group_path[len] =0 ; - group_name =basename (group_path); + group_name =g_path_get_basename (group_path);if (sscanf (group_name,"%d" , &groupid) !=1 ) {error_setg_errno (errp, errno,"failed to read %s" , group_path);return -errno;Signature · 1 line
2.43.0
Cédric Le Goater
AppliedQuoted 8 lines · Cédric Le Goater
g_path_get_basename()is a portable utility function that has the advantage of not modifing the string argument. It also fixes a compile breakage with the Musl C library reported in [1].[1] https://lore.kernel.org/all/[email protected]/
Reported-by Khem Raj <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Applied to vfio-next.
Thanks,
C.
Quoted 27 lines
--- hw/vfio/container.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/vfio/container.c +3
-2@@ -869,7 +869,8 @@ static void vfio_put_base_device(VFIODevice *vbasedev)static int vfio_device_groupid (VFIODevice *vbasedev,Error **errp) { -char *tmp, group_path[PATH_MAX ], *group_name; +char *tmp, group_path[PATH_MAX ]; + g_autofree char *group_name = NULL;int ret, groupid;ssize_t len;@@ -885,7 +886,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) group_path[len] =0 ; - group_name =basename (group_path); + group_name =g_path_get_basename (group_path);if (sscanf (group_name,"%d" , &groupid) !=1 ) {error_setg_errno (errp, errno,"failed to read %s" , group_path);return -errno;
Quoted 11 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: [PATCH] vfio/container: Replace basename withg_path_get_basename
g_path_get_basename()is a portable utility function that has the advantage of not modifing the string argument. It also fixes a compile breakage with the Musl C library reported in [1].
Quoted 5 lines
[1] https://lore.kernel.org/all/20231212010228.2701544-1-
[email protected]/Reported-by Khem Raj <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Thanks
Zhenzhong
Quoted 33 lines
---
hw/vfio/container.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)hw/vfio/container.c +0
-0index
688cf23bab88f85246378bc5a7da3c51ea6b79d9..8d334f52f2438d05f632502e07ffd4dc2ec76cb5100644hw/vfio/container.c +3
-2@@ -869,7 +869,8 @@ static void vfio_put_base_device(VFIODevice *vbasedev)static int vfio_device_groupid (VFIODevice *vbasedev,Error **errp) { -char *tmp, group_path[PATH_MAX ], *group_name; +char *tmp, group_path[PATH_MAX ]; + g_autofree char *group_name = NULL;int ret, groupid;ssize_t len;@@ -885,7 +886,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp) group_path[len] =0 ; - group_name =basename (group_path); + group_name =g_path_get_basename (group_path);if (sscanf (group_name,"%d" , &groupid) !=1 ) {error_setg_errno (errp, errno,"failed to read %s" , group_path);return -errno;--
2.43.0