[PATCH net-next v4 10/10] net: netconsole: fix wrong warning

Breno Leitao posted 10 patches 1 month, 4 weeks ago
There is a newer version of this series
[PATCH net-next v4 10/10] net: netconsole: fix wrong warning
Posted by Breno Leitao 1 month, 4 weeks ago
A warning is triggered when there is insufficient space in the buffer
for userdata. However, this is not an issue since userdata will be sent
in the next iteration.

Current warning message:

    ------------[ cut here ]------------
     WARNING: CPU: 13 PID: 3013042 at drivers/net/netconsole.c:1122 write_ext_msg+0x3b6/0x3d0
      ? write_ext_msg+0x3b6/0x3d0
      console_flush_all+0x1e9/0x330

The code incorrectly issues a warning when this_chunk is zero, which is
a valid scenario. The warning should only be triggered when this_chunk
is negative.

Signed-off-by: Breno Leitao <leitao@debian.org>
Fixes: 1ec9daf95093 ("net: netconsole: append userdata to fragmented netconsole messages")
---
 drivers/net/netconsole.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index f724511cf567..4ea44a2f48f7 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1164,8 +1164,14 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf,
 
 			this_chunk = min(userdata_len - sent_userdata,
 					 MAX_PRINT_CHUNK - preceding_bytes);
-			if (WARN_ON_ONCE(this_chunk <= 0))
+			if (WARN_ON_ONCE(this_chunk < 0))
+				/* this_chunk could be zero if all the previous
+				 * message used all the buffer. This is not a
+				 * problem, userdata will be sent in the next
+				 * iteration
+				 */
 				return;
+
 			memcpy(buf + this_header + this_offset,
 			       userdata + sent_userdata,
 			       this_chunk);
-- 
2.43.5
Re: [PATCH net-next v4 10/10] net: netconsole: fix wrong warning
Posted by Simon Horman 1 month, 4 weeks ago
On Mon, Sep 30, 2024 at 06:12:09AM -0700, Breno Leitao wrote:
> A warning is triggered when there is insufficient space in the buffer
> for userdata. However, this is not an issue since userdata will be sent
> in the next iteration.
> 
> Current warning message:
> 
>     ------------[ cut here ]------------
>      WARNING: CPU: 13 PID: 3013042 at drivers/net/netconsole.c:1122 write_ext_msg+0x3b6/0x3d0
>       ? write_ext_msg+0x3b6/0x3d0
>       console_flush_all+0x1e9/0x330
> 
> The code incorrectly issues a warning when this_chunk is zero, which is
> a valid scenario. The warning should only be triggered when this_chunk
> is negative.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> Fixes: 1ec9daf95093 ("net: netconsole: append userdata to fragmented netconsole messages")

Reviewed-by: Simon Horman <horms@kernel.org>