Skip to contentSkip to conversation

led-class-flash: fix -Wrestrict warning

PATCH Superseded Arnd Bergmann 3 participants 4 messages Sep 27, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 led-class-flash: fix -Wrestrict warning

From: Arnd Bergmann <[email protected]>

drivers/leds/led-class-flash.c: In function 'flash_fault_show':
drivers/leds/led-class-flash.c:210:16: error: 'sprintf' argument 3 overlaps destination object 'buf' [-Werror=restrict]

  210 |         return sprintf(buf, "%s\n", buf);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~

drivers/leds/led-class-flash.c:187:54: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
187 | struct device_attribute *attr, char *buf)
| ~~~~~~^~~
cc1: all warnings being treated as errors
make[5]: *** [scripts/Makefile.build:277: drivers/leds/led-class-flash.o] Error 1
make[5]: Target '__build' not remade because of errors.
make[4]: *** [scripts/Makefile.build:540: drivers/leds] Error 2
drivers/thunderbolt/xdomain.c: In function 'modalias_show':
drivers/thunderbolt/xdomain.c:733:16: error: 'sprintf' argument 3 overlaps destination object 'buf' [-Werror=restrict]

  733 |         return sprintf(buf, "%s\n", buf);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/thunderbolt/xdomain.c:727:36: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  727 |                              char *buf)
      |                              ~~~~~~^~~
---
 drivers/leds/led-class-flash.c | 2 +-
 drivers/thunderbolt/xdomain.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/leds/led-class-flash.c +1 -1
index 185e17055317..6fe9d700dfef 100644
@@ -207,7 +207,7 @@ static ssize_t flash_fault_show(struct device *dev,
 		mask <<= 1;
 	}
 
-	return sprintf(buf, "%s\n", buf);
+	return strlen(strcat(buf, "\n"));
 }
 static DEVICE_ATTR_RO(flash_fault);
 
drivers/thunderbolt/xdomain.c +1 -1
index d66ea4d616fd..eff32499610f 100644
@@ -730,7 +730,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
 
 	/* Full buffer size except new line and null termination */
 	get_modalias(svc, buf, PAGE_SIZE - 2);
-	return sprintf(buf, "%s\n", buf);
+	return strlen(strcat(buf, "\n"));
 }
 static DEVICE_ATTR_RO(modalias);
 
Signature · 1 line
2.29.2
#1 lore raw
Quoted 56 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

drivers/leds/led-class-flash.c: In function 'flash_fault_show':
drivers/leds/led-class-flash.c:210:16: error: 'sprintf' argument 3 overlaps destination object 'buf' [-Werror=restrict]

  210 |         return sprintf(buf, "%s\n", buf);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~

drivers/leds/led-class-flash.c:187:54: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
187 | struct device_attribute *attr, char *buf)
| ~~~~~~^~~
cc1: all warnings being treated as errors
make[5]: *** [scripts/Makefile.build:277: drivers/leds/led-class-flash.o] Error 1
make[5]: Target '__build' not remade because of errors.
make[4]: *** [scripts/Makefile.build:540: drivers/leds] Error 2
drivers/thunderbolt/xdomain.c: In function 'modalias_show':
drivers/thunderbolt/xdomain.c:733:16: error: 'sprintf' argument 3 overlaps destination object 'buf' [-Werror=restrict]

  733 |         return sprintf(buf, "%s\n", buf);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/thunderbolt/xdomain.c:727:36: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  727 |                              char *buf)
      |                              ~~~~~~^~~
---
 drivers/leds/led-class-flash.c | 2 +-
 drivers/thunderbolt/xdomain.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/leds/led-class-flash.c +1 -1
index 185e17055317..6fe9d700dfef 100644
@@ -207,7 +207,7 @@ static ssize_t flash_fault_show(struct device *dev,
 		mask <<= 1;
 	}
 
-	return sprintf(buf, "%s\n", buf);
+	return strlen(strcat(buf, "\n"));
 }
 static DEVICE_ATTR_RO(flash_fault);
 
drivers/thunderbolt/xdomain.c +1 -1
index d66ea4d616fd..eff32499610f 100644
@@ -730,7 +730,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
 
 	/* Full buffer size except new line and null termination */
 	get_modalias(svc, buf, PAGE_SIZE - 2);
-	return sprintf(buf, "%s\n", buf);
+	return strlen(strcat(buf, "\n"));
 }
 static DEVICE_ATTR_RO(modalias);
 
Signature · 1 line
2.29.2

You also have a thunderbolt change in here as well :(

#2 lore raw
Quoted 23 lines · Greg Kroah-Hartman
Quoted 15 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

drivers/leds/led-class-flash.c: In function 'flash_fault_show':
drivers/leds/led-class-flash.c:210:16: error: 'sprintf' argument 3 overlaps destination object 'buf' [-Werror=restrict]

  210 |         return sprintf(buf, "%s\n", buf);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~

drivers/leds/led-class-flash.c:187:54: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
187 | struct device_attribute *attr, char *buf)
| ~~~~~~^~~
cc1: all warnings being treated as errors
make[5]: *** [scripts/Makefile.build:277: drivers/leds/led-class-flash.o] Error 1
make[5]: Target '__build' not remade because of errors.
make[4]: *** [scripts/Makefile.build:540: drivers/leds] Error 2
drivers/thunderbolt/xdomain.c: In function 'modalias_show':
drivers/thunderbolt/xdomain.c:733:16: error: 'sprintf' argument 3 overlaps destination object 'buf' [-Werror=restrict]

Quoted 5 lines
  733 |         return sprintf(buf, "%s\n", buf);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~

drivers/thunderbolt/xdomain.c:727:36: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
727 | char *buf)

Quoted 1 line

You also have a thunderbolt change in here as well :(

Oh, and I forgot to explain the change, clearly this one was meant to go into the 'rework, then send' pile of my fixes.

v2 coming in a bit.

Arnd

#3 lore raw
In reply to Arnd Bergmann

Hi!

Quoted 11 lines
---
 drivers/leds/led-class-flash.c | 2 +-
 drivers/thunderbolt/xdomain.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/leds/led-class-flash.c +0 -0
index 185e17055317..6fe9d700dfef 100644

drivers/leds/led-class-flash.c static ssize_t flash_fault_show(struct device *dev, · line 213

Quoted 8 lines
drivers/leds/led-class-flash.c +1 -1
@@ -207,7 +207,7 @@ static ssize_t flash_fault_show(struct device *dev,
 		mask <<= 1;
 	}
 
-	return sprintf(buf, "%s\n", buf);
+	return strlen(strcat(buf, "\n"));
 }
 static DEVICE_ATTR_RO(flash_fault);
 

That's not just a warning. .. the code is crazy. I'll take it if you split it from the thunderbolt change.

Best regards,
Pavel

Quoted 15 lines
drivers/thunderbolt/xdomain.c +1 -1
index d66ea4d616fd..eff32499610f 100644
@@ -730,7 +730,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
 
 	/* Full buffer size except new line and null termination */
 	get_modalias(svc, buf, PAGE_SIZE - 2);
-	return sprintf(buf, "%s\n", buf);
+	return strlen(strcat(buf, "\n"));
 }
 static DEVICE_ATTR_RO(modalias);
 
Signature · 1 line
2.29.2
Signature · 1 line
http://www.livejournal.com/~pavelmachek