Target-devel archive mirror
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: Chaitanya Kulkarni <chaitanyak@nvidia.com>,
	Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"target-devel@vger.kernel.org" <target-devel@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Abaci Robot <abaci@linux.alibaba.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>
Subject: Re: [PATCH] scsi: target: return -ENOMEM when kzalloc failed
Date: Thu, 30 Mar 2023 20:00:54 +0900	[thread overview]
Message-ID: <97a2129c-b1d8-de74-014a-07e89ae95b30@opensource.wdc.com> (raw)
In-Reply-To: <73695d8e-a779-3c9c-5a46-b5a23381dff2@nvidia.com>

On 3/30/23 16:59, Chaitanya Kulkarni wrote:
> On 3/29/23 19:38, Jiapeng Chong wrote:
>> The driver is using -1 instead of the -ENOMEM defined macro to specify
>> that a buffer allocation failed.
>>
>> drivers/target/iscsi/iscsi_target.c:691 iscsi_target_init_module() warn: returning -1 instead of -ENOMEM is sloppy.
>>
>> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
>> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4644
>> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
>> ---
>>   drivers/target/iscsi/iscsi_target.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
>> index 834cce50f9b0..d3a40c3caaf5 100644
>> --- a/drivers/target/iscsi/iscsi_target.c
>> +++ b/drivers/target/iscsi/iscsi_target.c
>> @@ -688,7 +688,7 @@ static int __init iscsi_target_init_module(void)
>>   	pr_debug("iSCSI-Target "ISCSIT_VERSION"\n");
>>   	iscsit_global = kzalloc(sizeof(*iscsit_global), GFP_KERNEL);
>>   	if (!iscsit_global)
>> -		return -1;
>> +		return -ENOMEM;
>>   
>>   	spin_lock_init(&iscsit_global->ts_bitmap_lock);
>>   	mutex_init(&auth_id_lock);
> 
> you can also just use goto out, it has return -ENOMEM, no biggy..
> Also, it will be useful to print the error message here as we
> are making this change..

Printing an error message for allocation failures is frowned upon. Checkpatch
will complain.

-- 
Damien Le Moal
Western Digital Research


      reply	other threads:[~2023-03-30 11:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30  2:38 [PATCH] scsi: target: return -ENOMEM when kzalloc failed Jiapeng Chong
2023-03-30  7:59 ` Chaitanya Kulkarni
2023-03-30 11:00   ` Damien Le Moal [this message]

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=97a2129c-b1d8-de74-014a-07e89ae95b30@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=abaci@linux.alibaba.com \
    --cc=chaitanyak@nvidia.com \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=target-devel@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 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 read-only IMAP folder(s) and NNTP newsgroup(s).