linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: wharms@bfs.de
Cc: sathya.prakash@broadcom.com, chaitra.basappa@broadcom.com,
	suganath-prabu.subramani@broadcom.com, jejb@linux.vnet.ibm.com,
	martin.petersen@oracle.com, MPT-FusionLinux.pdl@broadcom.com,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()'
Date: Mon, 7 Aug 2017 10:45:35 +0200	[thread overview]
Message-ID: <625e7538-3834-0c9b-55bf-9aa460ded9bb@wanadoo.fr> (raw)
In-Reply-To: <5988240C.1050702@bfs.de>

Le 07/08/2017 à 10:25, walter harms a écrit :
>
> Am 07.08.2017 00:51, schrieb Christophe JAILLET:
>> In the lines above this test, 8 'kzalloc' are performed, but only 7 results
>> are tested.
>>
>> Add the missing one (i.e. '!ioc->port_enable_cmds.reply').
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>>   drivers/scsi/mpt3sas/mpt3sas_base.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> index 1a5b6e40fb5c..8a44636ab0b5 100644
>> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
>> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
>> @@ -5494,10 +5494,10 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
>>   	ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
>>   	mutex_init(&ioc->ctl_cmds.mutex);
>>   
>> -	if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
>> -	    !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
>> -	    !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
>> -	    !ioc->ctl_cmds.sense) {
>> +	if (!ioc->base_cmds.reply || !ioc->port_enable_cmds.reply ||
>> +	    !ioc->transport_cmds.reply || !ioc->scsih_cmds.reply ||
>> +	    !ioc->tm_cmds.reply || !ioc->config_cmds.reply ||
>> +	    !ioc->ctl_cmds.reply || !ioc->ctl_cmds.sense) {
>>   		r = -ENOMEM;
>>   		goto out_free_resources;
>>   	}
>
> obviously it is better to follow the pattern "malloc() , check".
Agreed, but it is also more verbose. Leavig it as-is, is IMHO, good enough.

> Even the programmer lost track.
>
> Bonus points if you malloc the buffers in one step.
Most of the allocation are 'kzalloc(ioc->reply_sz, GFP_KERNEL);', so a 
kcalloc could be used instead.
However, the 'kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);' breaks this 
logic and allocating all at once would lead to spaghetti code for no reason.

Moreover, I don't have any idea how big can be 'ioc->reply_sz', even if 
I guess it should be small.
So allocating all at once, could fail where several steps would work.

So I won't play for the bonus points :).

Best regards.
CJ

> just my 2 cents,
>
> re,
>   wh
>
>
>

  reply	other threads:[~2017-08-07  8:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-06 22:37 [PATCH 0/3] power: supply: charger-manager: 1 fix and 2 minor clean-ups Christophe JAILLET
2017-08-06 22:37 ` [PATCH 1/3] power: supply: charger-manager: Fix a NULL pointer dereference in 'charger_manager_probe()' Christophe JAILLET
2017-08-06 22:37 ` [PATCH 2/3] power: supply: charger-manager: Fix a comment Christophe JAILLET
2017-08-06 22:37 ` [PATCH 3/3] power: supply: charger-manager: Slighly simplify code Christophe JAILLET
2017-08-06 22:51 ` [PATCH] scsi: mpt3sas: Fix memory allocation failure test in 'mpt3sas_base_attach()' Christophe JAILLET
2017-08-07  8:25   ` walter harms
2017-08-07  8:45     ` Christophe JAILLET [this message]
2017-08-12 18:03 ` [PATCH 0/3] power: supply: charger-manager: 1 fix and 2 minor clean-ups Sebastian Reichel

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=625e7538-3834-0c9b-55bf-9aa460ded9bb@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=MPT-FusionLinux.pdl@broadcom.com \
    --cc=chaitra.basappa@broadcom.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=sathya.prakash@broadcom.com \
    --cc=suganath-prabu.subramani@broadcom.com \
    --cc=wharms@bfs.de \
    /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;
as well as URLs for NNTP newsgroup(s).