Re: [Intel-wired-lan] [PATCH v5 iwl-next] i40e: Use correct buffer size in i40e_dbg_command_read

From: Nelson, Shannon
Date: Tue Dec 19 2023 - 20:34:26 EST


On 12/17/2023 9:54 PM, Pucha, HimasekharX Reddy wrote:

-----Original Message-----
From: Intel-wired-lan <intel-wired-lan-bounces@xxxxxxxxxx> On Behalf Of Kunwu Chan
Sent: Friday, December 8, 2023 8:50 AM
To: Brandeburg, Jesse <jesse.brandeburg@xxxxxxxxx>; Nguyen, Anthony L <anthony.l.nguyen@xxxxxxxxx>; davem@xxxxxxxxxxxxx; edumazet@xxxxxxxxxx; kuba@xxxxxxxxxx; pabeni@xxxxxxxxxx; jeffrey.t.kirsher@xxxxxxxxx; shannon.nelson@xxxxxxx
Cc: Kunwu Chan <chentao@xxxxxxxxxx>; Kunwu Chan <kunwu.chan@xxxxxxxxxxx>; netdev@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; Lobakin, Aleksander <aleksander.lobakin@xxxxxxxxx>; intel-wired-lan@xxxxxxxxxxxxxxxx; Simon Horman <horms@xxxxxxxxxx>
Subject: [Intel-wired-lan] [PATCH v5 iwl-next] i40e: Use correct buffer size in i40e_dbg_command_read

The size of "i40e_dbg_command_buf" is 256, the size of "name"
depends on "IFNAMSIZ", plus a null character and format size,
the total size is more than 256.

Improve readability and maintainability by replacing a hardcoded string
allocation and formatting by the use of the kasprintf() helper.

Fixes: 02e9c290814c ("i40e: debugfs interface")
Suggested-by: Simon Horman <horms@xxxxxxxxxx>
Suggested-by: Alexander Lobakin <aleksander.lobakin@xxxxxxxxx>
Suggested-by: Tony Nguyen <anthony.l.nguyen@xxxxxxxxx>
Cc: Kunwu Chan <kunwu.chan@xxxxxxxxxxx>
Signed-off-by: Kunwu Chan <chentao@xxxxxxxxxx>
---
v2
- Update the size calculation with IFNAMSIZ and sizeof(i40e_dbg_command_buf)
v3
- Use kasprintf to improve readability and maintainability
v4
- Fix memory leak in error path
v5
- Change the order of labels
---
.../net/ethernet/intel/i40e/i40e_debugfs.c | 20 ++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)


Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@xxxxxxxxx> (A Contingent worker at Intel)


Much of this debugfs command code was an early driver hack that probably never should have gone upstream in the form that it did. The i40e_dbg_command_buf itself was originally meant as a scratchpad to put the 'last command processed', which was not really very useful, and as a static global that might be written by any number of instances of i40e devices, was problematic from the beginning. Now, unless I'm mistaken, it looks like nothing is writing to the buffer at all anymore, so the buffer and the i40e_dbg_command_read() callback probably should just all go away rather than trying to pretty up some useless code.

sln