Skip to contentSkip to conversation

hw/arm/xilinx_zynq: Use strcasecmp to parse boot-mode option values

PATCH In review Peter Maydell 4 participants 6 messages Mar 27 – Mar 30 Arm/Zynq architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/arm/xilinx_zynq: Use strcasecmp to parse boot-mode option values

In zynq_set_boot_mode() where we parse the string the user has set the boot-mode option to, we use strncasecmp(str, "qspi", 4) and so on. This is wrong, because it means that we will ignore any trailing junk on the end of the option string, and handle
-machine boot-mode=sdXYZZY
the same as
-machine boot-mode=sd

In the documentation we say:
Supported values are ``jtag``, ``sd``, ``qspi`` and ``nor``.
and that's obviously what we meant to implement.

The correct tool for this job is a simple strcasecmp operation. Switch to that.

We use the g_ascii_strcasecmp() rather than plain strcasecmp() because we're comparing ASCII strings here and don't want the potentially locale-specific behaviour that strcasecmp() implies (and we're trying to standardize on the glib function for this kind of string comparison).

Fixes 7df3747c92d13 ("hw/arm/xilinx_zynq: Add boot-mode property")

---
Kostiantyn: I sent this patch out while it was on my mind, but don't worry about conflicts with your series -- assuming your patchset goes in first I'll fix this one up later.

---
 hw/arm/xilinx_zynq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/arm/xilinx_zynq.c +4 -4
index d43f36b718..9dcded9219 100644
@@ -186,13 +186,13 @@ static void zynq_set_boot_mode(Object *obj, const char *str,
     ZynqMachineState *m = ZYNQ_MACHINE(obj);
     uint8_t mode = 0;
 
-    if (!strncasecmp(str, "qspi", 4)) {
+    if (!g_ascii_strcasecmp(str, "qspi")) {
         mode = 1;
-    } else if (!strncasecmp(str, "sd", 2)) {
+    } else if (!g_ascii_strcasecmp(str, "sd")) {
         mode = 5;
-    } else if (!strncasecmp(str, "nor", 3)) {
+    } else if (!g_ascii_strcasecmp(str, "nor")) {
         mode = 2;
-    } else if (!strncasecmp(str, "jtag", 4)) {
+    } else if (!g_ascii_strcasecmp(str, "jtag")) {
         mode = 0;
     } else {
         error_setg(errp, "%s boot mode not supported", str);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Peter Maydell

In zynq_set_boot_mode() where we parse the string the user has set the boot-mode option to, we use strncasecmp(str, "qspi", 4) and so on. This is wrong, because it means that we will ignore any trailing junk on the end of the option string, and handle
-machine boot-mode=sdXYZZY
the same as
-machine boot-mode=sd

In the documentation we say:
Supported values are ``jtag``, ``sd``, ``qspi`` and ``nor``.
and that's obviously what we meant to implement.

The correct tool for this job is a simple strcasecmp operation. Switch to that.

Quoted 8 lines

We use the g_ascii_strcasecmp() rather than plain strcasecmp() because we're comparing ASCII strings here and don't want the potentially locale-specific behaviour that strcasecmp() implies (and we're trying to standardize on the glib function for this kind of string comparison).

Fixes 7df3747c92d13 ("hw/arm/xilinx_zynq: Add boot-mode property")

Alistair

Quoted 34 lines

---
Kostiantyn: I sent this patch out while it was on my mind, but don't worry about conflicts with your series -- assuming your patchset goes in first I'll fix this one up later.

---
 hw/arm/xilinx_zynq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/arm/xilinx_zynq.c +4 -5
index d43f36b718..9dcded9219 100644
@@ -186,13 +186,13 @@ static void zynq_set_boot_mode(Object *obj, const char *str,
     ZynqMachineState *m = ZYNQ_MACHINE(obj);
     uint8_t mode = 0;
 
-    if (!strncasecmp(str, "qspi", 4)) {
+    if (!g_ascii_strcasecmp(str, "qspi")) {
         mode = 1;
-    } else if (!strncasecmp(str, "sd", 2)) {
+    } else if (!g_ascii_strcasecmp(str, "sd")) {
         mode = 5;
-    } else if (!strncasecmp(str, "nor", 3)) {
+    } else if (!g_ascii_strcasecmp(str, "nor")) {
         mode = 2;
-    } else if (!strncasecmp(str, "jtag", 4)) {
+    } else if (!g_ascii_strcasecmp(str, "jtag")) {
         mode = 0;
     } else {
         error_setg(errp, "%s boot mode not supported", str);
--

2.43.0

Reviewed-by
#2 lore raw
Quoted 68 lines · Alistair Francis
Quoted 16 lines · Peter Maydell

In zynq_set_boot_mode() where we parse the string the user has set the boot-mode option to, we use strncasecmp(str, "qspi", 4) and so on. This is wrong, because it means that we will ignore any trailing junk on the end of the option string, and handle
-machine boot-mode=sdXYZZY
the same as
-machine boot-mode=sd

In the documentation we say:
Supported values are ``jtag``, ``sd``, ``qspi`` and ``nor``.
and that's obviously what we meant to implement.

The correct tool for this job is a simple strcasecmp operation. Switch to that.

Quoted 8 lines

We use the g_ascii_strcasecmp() rather than plain strcasecmp() because we're comparing ASCII strings here and don't want the potentially locale-specific behaviour that strcasecmp() implies (and we're trying to standardize on the glib function for this kind of string comparison).

Fixes 7df3747c92d13 ("hw/arm/xilinx_zynq: Add boot-mode property")

Alistair

hw/arm/xilinx_zynq.c static void zynq_set_boot_mode(Object *obj, const

Quoted 13 lines

---
Kostiantyn: I sent this patch out while it was on my mind, but don't worry about conflicts with your series -- assuming your patchset goes in first I'll fix this one up later.

---
 hw/arm/xilinx_zynq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/arm/xilinx_zynq.c +0 -0
index d43f36b718..9dcded9219 100644
@@ -186,13 +186,13 @@ static void zynq_set_boot_mode(Object *obj, const

char *str,

Quoted 21 lines
hw/arm/xilinx_zynq.c +4 -5
     ZynqMachineState *m = ZYNQ_MACHINE(obj);
     uint8_t mode = 0;
 
-    if (!strncasecmp(str, "qspi", 4)) {
+    if (!g_ascii_strcasecmp(str, "qspi")) {
         mode = 1;
-    } else if (!strncasecmp(str, "sd", 2)) {
+    } else if (!g_ascii_strcasecmp(str, "sd")) {
         mode = 5;
-    } else if (!strncasecmp(str, "nor", 3)) {
+    } else if (!g_ascii_strcasecmp(str, "nor")) {
         mode = 2;
-    } else if (!strncasecmp(str, "jtag", 4)) {
+    } else if (!g_ascii_strcasecmp(str, "jtag")) {
         mode = 0;
     } else {
         error_setg(errp, "%s boot mode not supported", str);
--

2.43.0

Reviewed-by on v1 1/1
#3 lore raw
In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

In zynq_set_boot_mode() where we parse the string the user has set the boot-mode option to, we use strncasecmp(str, "qspi", 4) and so on. This is wrong, because it means that we will ignore any trailing junk on the end of the option string, and handle
-machine boot-mode=sdXYZZY
the same as
-machine boot-mode=sd

In the documentation we say:
Supported values are ``jtag``, ``sd``, ``qspi`` and ``nor``.
and that's obviously what we meant to implement.

The correct tool for this job is a simple strcasecmp operation. Switch to that.

Quoted 8 lines

We use the g_ascii_strcasecmp() rather than plain strcasecmp() because we're comparing ASCII strings here and don't want the potentially locale-specific behaviour that strcasecmp() implies (and we're trying to standardize on the glib function for this kind of string comparison).

Fixes 7df3747c92d13 ("hw/arm/xilinx_zynq: Add boot-mode property")
Quoted 3 lines

Kostiantyn: I sent this patch out while it was on my mind, but don't worry about conflicts with your series -- assuming your patchset goes in first I'll fix this one up later.

No worries, go ahead since you can apply this even for 11.0; I'll take Kostiantyn's patches and handle the conflicts.

Paolo

#4 lore raw
Quoted 26 lines · Paolo Bonzini
Quoted 15 lines · Peter Maydell

In zynq_set_boot_mode() where we parse the string the user has set the boot-mode option to, we use strncasecmp(str, "qspi", 4) and so on. This is wrong, because it means that we will ignore any trailing junk on the end of the option string, and handle
-machine boot-mode=sdXYZZY
the same as
-machine boot-mode=sd

In the documentation we say:
Supported values are ``jtag``, ``sd``, ``qspi`` and ``nor``.
and that's obviously what we meant to implement.

The correct tool for this job is a simple strcasecmp operation. Switch to that.

Quoted 8 lines

We use the g_ascii_strcasecmp() rather than plain strcasecmp() because we're comparing ASCII strings here and don't want the potentially locale-specific behaviour that strcasecmp() implies (and we're trying to standardize on the glib function for this kind of string comparison).

Fixes 7df3747c92d13 ("hw/arm/xilinx_zynq: Add boot-mode property")
Quoted 8 lines
Quoted 3 lines

Kostiantyn: I sent this patch out while it was on my mind, but don't worry about conflicts with your series -- assuming your patchset goes in first I'll fix this one up later.

No worries, go ahead since you can apply this even for 11.0; I'll take Kostiantyn's patches and handle the conflicts.

OK, great. I'm going to do a pullreq before rc2, so I'll put this in there. Or if you're going to take Kostiantyn's series and send it out for rc2 then feel free to put this patch in there instead of the one that fixes up this file.

thanks
-- PMM

#5 lore raw
Quoted 4 lines · Peter Maydell

OK, great. I'm going to do a pullreq before rc2, so I'll put this in there. Or if you're going to take Kostiantyn's series and send it out for rc2 then feel free to put this patch in there instead of the one that fixes up this file.

I wasn't planning to send his patches until after the release, since alone they don't do much (they're not enough to allow the MSVC build to complete).

Paolo