Skip to contentSkip to conversation

drivers/xen/xenbus: Replace deprecated strcpy in xenbus_transaction_end

PATCH Superseded Thorsten Blum 3 participants 6 messages Oct 12, 2025 – Oct 13, 2025 Xen hypervisor interface

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/xen/xenbus: Replace deprecated strcpy in xenbus_transaction_end

strcpy() is deprecated; use strscpy() instead. Fix the function comment and use bool instead of int while we're at it.

---
 drivers/xen/xenbus/xenbus_xs.c | 9 +++------
 include/xen/xenbus.h           | 2 +-
 2 files changed, 4 insertions(+), 7 deletions(-)
drivers/xen/xenbus/xenbus_xs.c +3 -6
index 528682bf0c7f..970302b3dcc6 100644
@@ -546,16 +546,13 @@ int xenbus_transaction_start(struct xenbus_transaction *t)
 EXPORT_SYMBOL_GPL(xenbus_transaction_start);
 
 /* End a transaction.
- * If abandon is true, transaction is discarded instead of committed.
+ * If abort is true, transaction is discarded instead of committed.
  */
-int xenbus_transaction_end(struct xenbus_transaction t, int abort)
+int xenbus_transaction_end(struct xenbus_transaction t, bool abort)
 {
 	char abortstr[2];
 
-	if (abort)
-		strcpy(abortstr, "F");
-	else
-		strcpy(abortstr, "T");
+	strscpy(abortstr, abort ? "F" : "T");
 
 	return xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL));
 }
include/xen/xenbus.h +1 -1
index 7dab04cf4a36..c94caf852aea 100644
@@ -158,7 +158,7 @@ int xenbus_exists(struct xenbus_transaction t,
 		  const char *dir, const char *node);
 int xenbus_rm(struct xenbus_transaction t, const char *dir, const char *node);
 int xenbus_transaction_start(struct xenbus_transaction *t);
-int xenbus_transaction_end(struct xenbus_transaction t, int abort);
+int xenbus_transaction_end(struct xenbus_transaction t, bool abort);
 
 /* Single read and scanf: returns -errno or num scanned if > 0. */
 __scanf(4, 5)
Signature · 1 line
2.51.0
#1 lore raw
Quoted 8 lines · Thorsten Blum
drivers/xen/xenbus/xenbus_xs.c +1 -1
@@ -546,16 +546,13 @@ int xenbus_transaction_start(struct xenbus_transaction *t)
 EXPORT_SYMBOL_GPL(xenbus_transaction_start);
 
 /* End a transaction.
- * If abandon is true, transaction is discarded instead of committed.
+ * If abort is true, transaction is discarded instead of committed.

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 558

Quoted 10 lines
drivers/xen/xenbus/xenbus_xs.c +1 -5
  */
-int xenbus_transaction_end(struct xenbus_transaction t, int abort)
+int xenbus_transaction_end(struct xenbus_transaction t, bool abort)
 {
 	char abortstr[2];
 
-	if (abort)
-		strcpy(abortstr, "F");
-	else
-		strcpy(abortstr, "T");

While at least in principle a compiler might be able to transform this into code not using any library function at all, ...

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 555

Quoted 1 line
drivers/xen/xenbus/xenbus_xs.c +1 -0
+	strscpy(abortstr, abort ? "F" : "T");

... the use of a n on-standard function (without equivalent compiler builtin) doesn't permit this. IOW why not simply switch to e.g.

    char abortstr[2] = { [0] = abort ? 'F' : 'T' };

Jan

maintainer
#2 lore raw
Quoted 23 lines · Jan Beulich
Quoted 8 lines · Thorsten Blum
drivers/xen/xenbus/xenbus_xs.c +1 -1
@@ -546,16 +546,13 @@ int xenbus_transaction_start(struct xenbus_transaction *t)
  EXPORT_SYMBOL_GPL(xenbus_transaction_start);
 
  /* End a transaction.
- * If abandon is true, transaction is discarded instead of committed.
+ * If abort is true, transaction is discarded instead of committed.

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 558

Quoted 10 lines
drivers/xen/xenbus/xenbus_xs.c +1 -5
   */
-int xenbus_transaction_end(struct xenbus_transaction t, int abort)
+int xenbus_transaction_end(struct xenbus_transaction t, bool abort)
  {
  	char abortstr[2];
 
-	if (abort)
-		strcpy(abortstr, "F");
-	else
-		strcpy(abortstr, "T");

While at least in principle a compiler might be able to transform this into code not using any library function at all, ...

Quoted 6 lines

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 555

Quoted 1 line
drivers/xen/xenbus/xenbus_xs.c +1 -0
+	strscpy(abortstr, abort ? "F" : "T");

... the use of a n on-standard function (without equivalent compiler builtin) doesn't permit this. IOW why not simply switch to e.g.

     char abortstr[2] = { [0] = abort ? 'F' : 'T' };

I would even go further and drop abortstr[] completely:

drivers/xen/xenbus/xenbus_xs.c +2 -8
index 528682bf0c7f..c891af7165f5 100644
@@ -550,14 +550,8 @@ EXPORT_SYMBOL_GPL(xenbus_transaction_start);
  */
 int xenbus_transaction_end(struct xenbus_transaction t, int abort)
 {
-       char abortstr[2];
-
-       if (abort)
-               strcpy(abortstr, "F");
-       else
-               strcpy(abortstr, "T");
-
-       return xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL));
+       return xs_error(xs_single(t, XS_TRANSACTION_END, abort ? "F" : "T",
+                       NULL));
 }
 EXPORT_SYMBOL_GPL(xenbus_transaction_end);
 

Juergen

#3 lore raw
Quoted 43 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 8 lines · Thorsten Blum
drivers/xen/xenbus/xenbus_xs.c +1 -1
@@ -546,16 +546,13 @@ int xenbus_transaction_start(struct xenbus_transaction *t)
  EXPORT_SYMBOL_GPL(xenbus_transaction_start);
 
  /* End a transaction.
- * If abandon is true, transaction is discarded instead of committed.
+ * If abort is true, transaction is discarded instead of committed.

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 558

Quoted 10 lines
drivers/xen/xenbus/xenbus_xs.c +1 -5
   */
-int xenbus_transaction_end(struct xenbus_transaction t, int abort)
+int xenbus_transaction_end(struct xenbus_transaction t, bool abort)
  {
  	char abortstr[2];
 
-	if (abort)
-		strcpy(abortstr, "F");
-	else
-		strcpy(abortstr, "T");

While at least in principle a compiler might be able to transform this into code not using any library function at all, ...

Quoted 6 lines

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 555

Quoted 1 line
drivers/xen/xenbus/xenbus_xs.c +1 -0
+	strscpy(abortstr, abort ? "F" : "T");

... the use of a n on-standard function (without equivalent compiler builtin) doesn't permit this. IOW why not simply switch to e.g.

     char abortstr[2] = { [0] = abort ? 'F' : 'T' };

I would even go further and drop abortstr[] completely:

drivers/xen/xenbus/xenbus_xs.c +0 -2
index 528682bf0c7f..c891af7165f5 100644
@@ -550,14 +550,8 @@ EXPORT_SYMBOL_GPL(xenbus_transaction_start);
   */
  int xenbus_transaction_end(struct xenbus_transaction t, int abort)
  {
-       char abortstr[2];
-

drivers/xen/xenbus/xenbus_xs.c EXPORT_SYMBOL_GPL(xenbus_transaction_start); · line 556

Quoted 10 lines
drivers/xen/xenbus/xenbus_xs.c +2 -6
-       if (abort)
-               strcpy(abortstr, "F");
-       else
-               strcpy(abortstr, "T");
-
-       return xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL));
+       return xs_error(xs_single(t, XS_TRANSACTION_END, abort ? "F" : "T",
+                       NULL));
  }
  EXPORT_SYMBOL_GPL(xenbus_transaction_end);

Hmm, which xs_single() indeed takes a const char *, it then casts away const- ness before handing to xs_talkv().

Jan

maintainer
#4 lore raw
Quoted 49 lines · Jan Beulich
Quoted 48 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 8 lines · Thorsten Blum
drivers/xen/xenbus/xenbus_xs.c +1 -1
@@ -546,16 +546,13 @@ int xenbus_transaction_start(struct xenbus_transaction *t)
   EXPORT_SYMBOL_GPL(xenbus_transaction_start);
 
   /* End a transaction.
- * If abandon is true, transaction is discarded instead of committed.
+ * If abort is true, transaction is discarded instead of committed.

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 558

Quoted 10 lines
drivers/xen/xenbus/xenbus_xs.c +1 -5
    */
-int xenbus_transaction_end(struct xenbus_transaction t, int abort)
+int xenbus_transaction_end(struct xenbus_transaction t, bool abort)
   {
   	char abortstr[2];
 
-	if (abort)
-		strcpy(abortstr, "F");
-	else
-		strcpy(abortstr, "T");

While at least in principle a compiler might be able to transform this into code not using any library function at all, ...

Quoted 6 lines

drivers/xen/xenbus/xenbus_xs.c int xenbus_transaction_start(struct xenbus_transaction *t) · line 555

Quoted 1 line
drivers/xen/xenbus/xenbus_xs.c +1 -0
+	strscpy(abortstr, abort ? "F" : "T");

... the use of a n on-standard function (without equivalent compiler builtin) doesn't permit this. IOW why not simply switch to e.g.

      char abortstr[2] = { [0] = abort ? 'F' : 'T' };

I would even go further and drop abortstr[] completely:

drivers/xen/xenbus/xenbus_xs.c +0 -7
index 528682bf0c7f..c891af7165f5 100644
@@ -550,14 +550,8 @@ EXPORT_SYMBOL_GPL(xenbus_transaction_start);
    */
   int xenbus_transaction_end(struct xenbus_transaction t, int abort)
   {
-       char abortstr[2];
-
-       if (abort)
-               strcpy(abortstr, "F");
-       else
-               strcpy(abortstr, "T");
-
Quoted 8 lines

drivers/xen/xenbus/xenbus_xs.c EXPORT_SYMBOL_GPL(xenbus_transaction_start); · line 556

Quoted 5 lines
drivers/xen/xenbus/xenbus_xs.c +2 -1
-       return xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL));
+       return xs_error(xs_single(t, XS_TRANSACTION_END, abort ? "F" : "T",
+                       NULL));
   }
   EXPORT_SYMBOL_GPL(xenbus_transaction_end);

Hmm, which xs_single() indeed takes a const char *, it then casts away const- ness before handing to xs_talkv().

Yes, the cast is needed as xs_talkv() can handle reads and writes. No problem in this case, as the string is only read by xs_talkv() (write type operation).

Juergen

#5 lore raw
Quoted 27 lines · Jürgen Groß
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Jürgen Groß

I would even go further and drop abortstr[] completely:

drivers/xen/xenbus/xenbus_xs.c +0 -6
index 528682bf0c7f..c891af7165f5 100644
@@ -550,14 +550,8 @@ EXPORT_SYMBOL_GPL(xenbus_transaction_start);
   */
  int xenbus_transaction_end(struct xenbus_transaction t, int abort)
  {
-       char abortstr[2];
-
-       if (abort)
-               strcpy(abortstr, "F");
-       else
-               strcpy(abortstr, "T");
Quoted 8 lines

drivers/xen/xenbus/xenbus_xs.c EXPORT_SYMBOL_GPL(xenbus_transaction_start); · line 556

Quoted 6 lines
drivers/xen/xenbus/xenbus_xs.c +2 -2
-
-       return xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL));
+       return xs_error(xs_single(t, XS_TRANSACTION_END, abort ? "F" : "T",
+                       NULL));
  }
  EXPORT_SYMBOL_GPL(xenbus_transaction_end);

Hmm, which xs_single() indeed takes a const char *, it then casts away const- ness before handing to xs_talkv().

Quoted 2 lines

Yes, the cast is needed as xs_talkv() can handle reads and writes. No problem in this case, as the string is only read by xs_talkv() (write type operation).

I'll submit a v2.

Thanks,
Thorsten