Skip to contentSkip to conversation

tools: usb: ffs-test: return the number of bytes written in pipe mode

PATCH In review Sasha Levin 3 participants 3 messages Oct 11 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: usb: ffs-test: return the number of bytes written in pipe mode

empty_out_buf() returns len, which the PAT_PIPE case never sets:

ffs-test.c:551:7: warning: variable 'len' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized]

Nothing sets pattern to PAT_PIPE, so the case is never reached and only the warning is visible. Return nbytes once the buffer has been written and flushed, and -1 if either fails.

Fixes 93f2aa4ddd25c ("USB: ffs-test: FunctionFS testing program")
Assisted-by LLM
---
 tools/usb/ffs-test.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/usb/ffs-test.c +3 -4
index f08060459b3f1..283db8979d67a 100644
@@ -528,7 +528,6 @@ empty_out_buf(struct thread *ignore, const void *buf, size_t nbytes)
 {
 	const __u8 *p;
 	__u8 expected;
-	ssize_t ret;
 	size_t len;
 
 	(void)ignore;
@@ -550,9 +549,9 @@ empty_out_buf(struct thread *ignore, const void *buf, size_t nbytes)
 		break;
 
 	case PAT_PIPE:
-		ret = fwrite(buf, nbytes, 1, stdout);
-		if (ret > 0)
-			fflush(stdout);
+		if (fwrite(buf, nbytes, 1, stdout) != 1 || fflush(stdout))
+			return -1;
+		len = nbytes;
 		break;
 
 invalid:
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

empty_out_buf() returns len, which the PAT_PIPE case never sets:

ffs-test.c:551:7: warning: variable 'len' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized]

Nothing sets pattern to PAT_PIPE, so the case is never reached and only the warning is visible. Return nbytes once the buffer has been written and flushed, and -1 if either fails.

Fixes 93f2aa4ddd25c ("USB: ffs-test: FunctionFS testing program")
Assisted-by LLM

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Acked-by on v1 1/1
#2 lore raw
In reply to Sasha Levin
Quoted 11 lines · Sasha Levin

empty_out_buf() returns len, which the PAT_PIPE case never sets:

ffs-test.c:551:7: warning: variable 'len' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized]

Nothing sets pattern to PAT_PIPE, so the case is never reached and only the warning is visible. Return nbytes once the buffer has been written and flushed, and -1 if either fails.

Fixes 93f2aa4ddd25c ("USB: ffs-test: FunctionFS testing program")
Assisted-by LLM
Quoted 29 lines
---
 tools/usb/ffs-test.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/usb/ffs-test.c +3 -4
index f08060459b3f1..283db8979d67a 100644
@@ -528,7 +528,6 @@ empty_out_buf(struct thread *ignore, const void *buf, size_t nbytes)
 {
 	const __u8 *p;
 	__u8 expected;
-	ssize_t ret;
 	size_t len;
 
 	(void)ignore;
@@ -550,9 +549,9 @@ empty_out_buf(struct thread *ignore, const void *buf, size_t nbytes)
 		break;
 
 	case PAT_PIPE:
-		ret = fwrite(buf, nbytes, 1, stdout);
-		if (ret > 0)
-			fflush(stdout);
+		if (fwrite(buf, nbytes, 1, stdout) != 1 || fflush(stdout))
+			return -1;
+		len = nbytes;
 		break;
 
 invalid:
Signature · 3 lines
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴィツ
«If at first you don’t succeed, give up skydiving»