Skip to contentSkip to conversation

vfio/container: Replace basename with g_path_get_basename

PATCH Applied Cédric Le Goater 4 participants 6 messages Dec 20, 2023 – Dec 21, 2023

lore
Share & tools
lore
#0 lore raw

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
index 688cf23bab88f85246378bc5a7da3c51ea6b79d9..8d334f52f2438d05f632502e07ffd4dc2ec76cb5 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

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

Eric

Quoted 27 lines
---
 hw/vfio/container.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/container.c +3 -2
index 688cf23bab88f85246378bc5a7da3c51ea6b79d9..8d334f52f2438d05f632502e07ffd4dc2ec76cb5 100644
@@ -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;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Cédric Le Goater

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 with g_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]/

---

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
index 688cf23bab88f85246378bc5a7da3c51ea6b79d9..8d334f52f2438d05f632502e07ffd4dc2ec76cb5 100644
@@ -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
#3 lore raw

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 with g_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]/

---

Quoted 7 lines

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.

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,
Zhao

Quoted 30 lines
  hw/vfio/container.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/container.c +3 -2
index 688cf23bab88f85246378bc5a7da3c51ea6b79d9..8d334f52f2438d05f632502e07ffd4dc2ec76cb5 100644
@@ -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
author Applied
#4 lore raw
In reply to Cédric Le Goater
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]/

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
index 688cf23bab88f85246378bc5a7da3c51ea6b79d9..8d334f52f2438d05f632502e07ffd4dc2ec76cb5 100644
@@ -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;
Reviewed-by on v1 1/1
#5 lore raw
In reply to Cédric Le Goater
Quoted 11 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: [PATCH] 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].

Quoted 5 lines

[1] https://lore.kernel.org/all/20231212010228.2701544-1-
[email protected]/

Thanks
Zhenzhong

Quoted 33 lines

---
hw/vfio/container.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/container.c +0 -0

index 688cf23bab88f85246378bc5a7da3c51ea6b79d9..8d334f52f2438d05f63250 2e07ffd4dc2ec76cb5 100644

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;

--
2.43.0