* [PATCH] thunderbolt: fix -Wrestrict warning
@ 2021-09-27 13:16 Arnd Bergmann
2021-09-28 9:32 ` Mika Westerberg
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2021-09-27 13:16 UTC (permalink / raw)
To: Andreas Noever, Michael Jamet, Mika Westerberg, Yehezkel Bernat
Cc: Arnd Bergmann, Greg Kroah-Hartman, Isaac Hazan, Lee Jones,
Rikard Falkeborn, linux-usb, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
gcc-11 warns when building with W=1:
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)
| ~~~~~~^~~
There is no need for the sprintf() here when a strcat() does
the same thing.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/thunderbolt/xdomain.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index d66ea4d616fd..eff32499610f 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -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);
--
2.29.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] thunderbolt: fix -Wrestrict warning
2021-09-27 13:16 [PATCH] thunderbolt: fix -Wrestrict warning Arnd Bergmann
@ 2021-09-28 9:32 ` Mika Westerberg
0 siblings, 0 replies; 2+ messages in thread
From: Mika Westerberg @ 2021-09-28 9:32 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andreas Noever, Michael Jamet, Yehezkel Bernat, Arnd Bergmann,
Greg Kroah-Hartman, Isaac Hazan, Lee Jones, Rikard Falkeborn,
linux-usb, linux-kernel
On Mon, Sep 27, 2021 at 03:16:11PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> gcc-11 warns when building with W=1:
>
> 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)
> | ~~~~~~^~~
>
> There is no need for the sprintf() here when a strcat() does
> the same thing.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-28 9:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 13:16 [PATCH] thunderbolt: fix -Wrestrict warning Arnd Bergmann
2021-09-28 9:32 ` Mika Westerberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).