mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Justin Stitt <justinstitt@google.com>,
	Kees Cook <keescook@chromium.org>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: dan.carpenter@linaro.org, kernel-janitors@vger.kernel.org,
	error27@gmail.com
Subject: Re: [PATCH] scsi: fcoe: Fix unsigned comparison with zero in store_ctlr_mode()
Date: Mon, 8 Jan 2024 13:31:20 +0100	[thread overview]
Message-ID: <565e1f78-b46d-4b22-8f9a-5a4bc7d23424@suse.de> (raw)
In-Reply-To: <20240102085245.600570-1-harshit.m.mogalapalli@oracle.com>

On 1/2/24 09:52, Harshit Mogalapalli wrote:
> ctlr->mode is of unsigned type, it is never less than zero.
> 
> Fix this by using an extra varibale called 'res', to store return value
> from sysfs_match_string() and assign that to ctlr->mode on the success
> path.
> 
> Fixes: edc22a7c8688 ("scsi: fcoe: Use sysfs_match_string() over fcoe_parse_mode()")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> ---
> This is based on static analysis with smatch and only compile tested.
> ---
>   drivers/scsi/fcoe/fcoe_sysfs.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
> index 408a806bf4c2..c64a085a7ee2 100644
> --- a/drivers/scsi/fcoe/fcoe_sysfs.c
> +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
> @@ -263,6 +263,7 @@ static ssize_t store_ctlr_mode(struct device *dev,
>   			       const char *buf, size_t count)
>   {
>   	struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
> +	int res;
>   
>   	if (count > FCOE_MAX_MODENAME_LEN)
>   		return -EINVAL;
> @@ -279,12 +280,13 @@ static ssize_t store_ctlr_mode(struct device *dev,
>   			return -ENOTSUPP;
>   		}
>   
> -		ctlr->mode = sysfs_match_string(fip_conn_type_names, buf);
> -		if (ctlr->mode < 0 || ctlr->mode == FIP_CONN_TYPE_UNKNOWN) {
> +		res = sysfs_match_string(fip_conn_type_names, buf);
> +		if (res < 0 || res == FIP_CONN_TYPE_UNKNOWN) {
>   			LIBFCOE_SYSFS_DBG(ctlr, "Unknown mode %s provided.\n",
>   					  buf);
>   			return -EINVAL;
>   		}
> +		ctlr->mode = res;
>   
>   		ctlr->f->set_fcoe_ctlr_mode(ctlr);
>   		LIBFCOE_SYSFS_DBG(ctlr, "Mode changed to %s.\n", buf);
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes


  reply	other threads:[~2024-01-08 12:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02  8:52 Harshit Mogalapalli
2024-01-08 12:31 ` Hannes Reinecke [this message]
2024-01-12  2:27 ` Martin K. Petersen
2024-01-17 20:10 ` 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=565e1f78-b46d-4b22-8f9a-5a4bc7d23424@suse.de \
    --to=hare@suse.de \
    --cc=dan.carpenter@linaro.org \
    --cc=error27@gmail.com \
    --cc=harshit.m.mogalapalli@oracle.com \
    --cc=jejb@linux.ibm.com \
    --cc=justinstitt@google.com \
    --cc=keescook@chromium.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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

all inboxes | Powered by JetHome®