From: David Laight <david.laight.linux@gmail.com>
To: Qianfeng Rong <rongqianfeng@vivo.com>
Cc: Don Brace <don.brace@microchip.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"open list:HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa)"
<storagedev@microchip.com>,
"open list:HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa)"
<linux-scsi@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/6] scsi: hpsa: use min()/min_t() to improve code
Date: Wed, 20 Aug 2025 18:57:38 +0100 [thread overview]
Message-ID: <20250820185738.098a49f9@pumpkin> (raw)
In-Reply-To: <deee5abe-1992-426d-a62d-51249014bdc9@vivo.com>
On Wed, 20 Aug 2025 20:50:08 +0800
Qianfeng Rong <rongqianfeng@vivo.com> wrote:
> 在 2025/8/20 20:02, David Laight 写道:
> > [You don't often get email from david.laight.linux@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> >
> > On Fri, 15 Aug 2025 20:16:04 +0800
> > Qianfeng Rong <rongqianfeng@vivo.com> 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@vivo.com>
> >> ---
> >> 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?
The thing to remember is that min_t(type, a, b) is just min((type)a, (type)b))
and you really would never write the latter.
David
>
> Best regards,
> Qianfeng
next prev parent reply other threads:[~2025-08-20 17:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 12:16 [PATCH 0/6] scsi: use min()/min_t()/max() to improve code Qianfeng Rong
2025-08-15 12:16 ` [PATCH 1/6] scsi: bfa: use min_t() " Qianfeng Rong
2025-08-20 12:13 ` David Laight
2025-08-15 12:16 ` [PATCH 2/6] scsi: hpsa: use min()/min_t() " Qianfeng Rong
2025-08-15 19:59 ` Don.Brace
2025-08-20 2:25 ` Martin K. Petersen
2025-08-20 12:02 ` David Laight
2025-08-20 12:50 ` Qianfeng Rong
2025-08-20 17:57 ` David Laight [this message]
2025-08-15 12:16 ` [PATCH 3/6] scsi: lpfc: use min() " Qianfeng Rong
2025-08-15 19:55 ` Justin Tee
2025-08-20 2:25 ` Martin K. Petersen
2025-08-15 12:16 ` [PATCH 4/6] scsi: megaraid_sas: use max() " Qianfeng Rong
2025-08-15 12:16 ` [PATCH 5/6] scsi: mpi3mr: use min() " Qianfeng Rong
2025-08-15 12:16 ` [PATCH 6/6] scsi: qla2xxx: " Qianfeng Rong
2025-08-26 2:33 ` (subset) [PATCH 0/6] scsi: use min()/min_t()/max() " Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250820185738.098a49f9@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=don.brace@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=rongqianfeng@vivo.com \
--cc=storagedev@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox