All of lore.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] [SCSI] scsi_transport_sas: check for allocation failure
Date: Fri, 08 Mar 2013 17:57:12 +0000	[thread overview]
Message-ID: <513A2678.5000803@interlog.com> (raw)
In-Reply-To: <20130308120215.GB18712@longonot.mountain>

On 13-03-08 07:02 AM, Dan Carpenter wrote:
> Static checkers complain that this allocation isn't checked.  We
> should return zero if the allocation fails.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
> index 1b68142..a022997 100644
> --- a/drivers/scsi/scsi_transport_sas.c
> +++ b/drivers/scsi/scsi_transport_sas.c
> @@ -379,9 +379,12 @@ sas_tlr_supported(struct scsi_device *sdev)
>   {
>   	const int vpd_len = 32;
>   	struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
> -	char *buffer = kzalloc(vpd_len, GFP_KERNEL);
> +	char *buffer;
>   	int ret = 0;
>
> +	buffer = kzalloc(vpd_len, GFP_KERNEL);
> +	if (!buffer)
> +		goto out;
>   	if (scsi_get_vpd_page(sdev, 0x90, buffer, vpd_len))
>   		goto out;
>

For 32 bytes, why not use the stack?

unsigned int
sas_tlr_supported(struct scsi_device *sdev)
{
         unsigned char buffer[32];
         struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
         int ret = 0;

         if (scsi_get_vpd_page(sdev, 0x90, buffer, sizeof(buffer)))
                 goto out;

         /*
          * The VPD Protocol Specific Logical Unit page (0x90) for SAS
          * has a 4 byte header and then one descriptor per device port.
          * The TLR bit is at offset 8 on each port descriptor.
          * We take the TLR value in the first descriptor.
          */
         ret = buffer[4 + 8] & 0x01;

  out:
         rdev->tlr_supported = ret;
         return ret;
}


Note the comment is changed.

Doug Gilbert



WARNING: multiple messages have this Message-ID (diff)
From: Douglas Gilbert <dgilbert@interlog.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] [SCSI] scsi_transport_sas: check for allocation failure
Date: Fri, 08 Mar 2013 12:57:12 -0500	[thread overview]
Message-ID: <513A2678.5000803@interlog.com> (raw)
In-Reply-To: <20130308120215.GB18712@longonot.mountain>

On 13-03-08 07:02 AM, Dan Carpenter wrote:
> Static checkers complain that this allocation isn't checked.  We
> should return zero if the allocation fails.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
> index 1b68142..a022997 100644
> --- a/drivers/scsi/scsi_transport_sas.c
> +++ b/drivers/scsi/scsi_transport_sas.c
> @@ -379,9 +379,12 @@ sas_tlr_supported(struct scsi_device *sdev)
>   {
>   	const int vpd_len = 32;
>   	struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
> -	char *buffer = kzalloc(vpd_len, GFP_KERNEL);
> +	char *buffer;
>   	int ret = 0;
>
> +	buffer = kzalloc(vpd_len, GFP_KERNEL);
> +	if (!buffer)
> +		goto out;
>   	if (scsi_get_vpd_page(sdev, 0x90, buffer, vpd_len))
>   		goto out;
>

For 32 bytes, why not use the stack?

unsigned int
sas_tlr_supported(struct scsi_device *sdev)
{
         unsigned char buffer[32];
         struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
         int ret = 0;

         if (scsi_get_vpd_page(sdev, 0x90, buffer, sizeof(buffer)))
                 goto out;

         /*
          * The VPD Protocol Specific Logical Unit page (0x90) for SAS
          * has a 4 byte header and then one descriptor per device port.
          * The TLR bit is at offset 8 on each port descriptor.
          * We take the TLR value in the first descriptor.
          */
         ret = buffer[4 + 8] & 0x01;

  out:
         rdev->tlr_supported = ret;
         return ret;
}


Note the comment is changed.

Doug Gilbert

  reply	other threads:[~2013-03-08 17:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-08 12:02 [patch] [SCSI] scsi_transport_sas: check for allocation failure Dan Carpenter
2013-03-08 12:02 ` Dan Carpenter
2013-03-08 17:57 ` Douglas Gilbert [this message]
2013-03-08 17:57   ` Douglas Gilbert
2013-03-08 19:58   ` Dan Carpenter
2013-03-08 19:58     ` Dan Carpenter
2013-03-08 22:50   ` James Bottomley
2013-03-08 23:25     ` Douglas Gilbert
2013-03-08 23:25       ` Douglas Gilbert
2013-03-11 13:10     ` Dan Carpenter
2013-03-11 13:10       ` Dan Carpenter
2013-03-11 14:48       ` Douglas Gilbert
2013-03-11 14:48         ` Douglas Gilbert
2013-03-11 15:10         ` James Bottomley

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=513A2678.5000803@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=JBottomley@parallels.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.