From: David Laight <david.laight.linux@gmail.com>
To: Qianfeng Rong <rongqianfeng@vivo.com>
Cc: Anil Gurumurthy <anil.gurumurthy@qlogic.com>,
Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org (open list:BROCADE BFA FC SCSI DRIVER),
linux-kernel@vger.kernel.org (open list)
Subject: Re: [PATCH 1/6] scsi: bfa: use min_t() to improve code
Date: Wed, 20 Aug 2025 13:13:03 +0100 [thread overview]
Message-ID: <20250820131303.1fa8e046@pumpkin> (raw)
In-Reply-To: <20250815121609.384914-2-rongqianfeng@vivo.com>
On Fri, 15 Aug 2025 20:16:03 +0800
Qianfeng Rong <rongqianfeng@vivo.com> wrote:
> Use min_t() to reduce the code in bfa_fcs_rport_update() and
> bfa_sgpg_mfree(), and improve readability.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
> drivers/scsi/bfa/bfa_fcs_rport.c | 8 +++-----
> drivers/scsi/bfa/bfa_svc.c | 5 +----
> 2 files changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/scsi/bfa/bfa_fcs_rport.c b/drivers/scsi/bfa/bfa_fcs_rport.c
> index d4bde9bbe75b..77dc7aaf5985 100644
> --- a/drivers/scsi/bfa/bfa_fcs_rport.c
> +++ b/drivers/scsi/bfa/bfa_fcs_rport.c
> @@ -11,7 +11,6 @@
> /*
> * rport.c Remote port implementation.
> */
> -
> #include "bfad_drv.h"
> #include "bfad_im.h"
> #include "bfa_fcs.h"
> @@ -2555,10 +2554,9 @@ bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
> * - MAX receive frame size
> */
> rport->cisc = plogi->csp.cisc;
> - if (be16_to_cpu(plogi->class3.rxsz) < be16_to_cpu(plogi->csp.rxsz))
> - rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
> - else
> - rport->maxfrsize = be16_to_cpu(plogi->csp.rxsz);
> + rport->maxfrsize = min_t(typeof(rport->maxfrsize),
> + be16_to_cpu(plogi->class3.rxsz),
> + be16_to_cpu(plogi->csp.rxsz));
I think I want to nak that one.
If you are going to use min_t() the type has to be one than includes
all possible values of both arguments.
Using the type of the result is just plain wrong.
There is also pretty much no point casting the values to char/short types
unless you need the implicit masking.
The values are immediately promoted to 'signed int' before the comparison.
I also think that min() will accept an 'unsigned char/short' variable
for a comparison against a 'signed int'.
So, all in all, min() should be fine.
Avoiding the extra be16_to_cpu() is probably a gain.
The compiler may not always know the value doesn't change.
David
>
> bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
> bfa_trc(port->fcs, port->fabric->bb_credit);
> diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
> index df33afaaa673..2570793aae7f 100644
> --- a/drivers/scsi/bfa/bfa_svc.c
> +++ b/drivers/scsi/bfa/bfa_svc.c
> @@ -5202,10 +5202,7 @@ bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpg)
> */
> do {
> wqe = bfa_q_first(&mod->sgpg_wait_q);
> - if (mod->free_sgpgs < wqe->nsgpg)
> - nsgpg = mod->free_sgpgs;
> - else
> - nsgpg = wqe->nsgpg;
> + nsgpg = min_t(int, mod->free_sgpgs, wqe->nsgpg);
> bfa_sgpg_malloc(bfa, &wqe->sgpg_q, nsgpg);
> wqe->nsgpg -= nsgpg;
> if (wqe->nsgpg == 0) {
next prev parent reply other threads:[~2025-08-20 12:13 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 [this message]
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
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=20250820131303.1fa8e046@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=anil.gurumurthy@qlogic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=rongqianfeng@vivo.com \
--cc=sudarsana.kalluru@qlogic.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