Re: [PATCH 2/6] scsi: hpsa: use min()/min_t() to improve code
From: Qianfeng Rong
Date: Wed Aug 20 2025 - 08:55:14 EST
在 2025/8/20 20:02, David Laight 写道:
[You don't often get email from david.laight.linux@xxxxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
On Fri, 15 Aug 2025 20:16:04 +0800
Qianfeng Rong <rongqianfeng@xxxxxxxx> wrote:
Use min()/min_t() to reduce the code in complete_scsi_command() and
hpsa_vpd_page_supported(), and improve readability.
Signed-off-by: Qianfeng Rong <rongqianfeng@xxxxxxxx>
---
drivers/scsi/hpsa.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index c73a71ac3c29..95dfcbac997f 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -2662,10 +2662,8 @@ static void complete_scsi_command(struct CommandList *cp)
case CMD_TARGET_STATUS:
cmd->result |= ei->ScsiStatus;
/* copy the sense data */
- if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo))
- sense_data_size = SCSI_SENSE_BUFFERSIZE;
- else
- sense_data_size = sizeof(ei->SenseInfo);
+ sense_data_size = min_t(unsigned long, SCSI_SENSE_BUFFERSIZE,
+ sizeof(ei->SenseInfo));
Why min_t() ?
A plain min() should be fine.
If it isn't you should really need to justify why the type of one parameter
can't be changes before using min_t().
SCSI_SENSE_BUFFERSIZE is a macro definition and is generally of type int.
The return type of sizeof(ei->SenseInfo) is size_t, so I used min_t()
here. However, as you mentioned, min() can also be used. Do I need to
send v2?
Best regards,
Qianfeng