mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: target: return -ENOMEM when kzalloc failed
@ 2023-03-30  2:38 Jiapeng Chong
  2023-03-30  7:59 ` Chaitanya Kulkarni
  0 siblings, 1 reply; 3+ messages in thread
From: Jiapeng Chong @ 2023-03-30  2:38 UTC (permalink / raw)
  To: martin.petersen
  Cc: linux-scsi, target-devel, linux-kernel, Jiapeng Chong, Abaci Robot

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);
-- 
2.20.1.7.g153144c


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: target: return -ENOMEM when kzalloc failed
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Chaitanya Kulkarni @ 2023-03-30  7:59 UTC (permalink / raw)
  To: Jiapeng Chong
  Cc: linux-scsi, target-devel, linux-kernel, Abaci Robot, martin.petersen

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..

irrespective of that :

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: target: return -ENOMEM when kzalloc failed
  2023-03-30  7:59 ` Chaitanya Kulkarni
@ 2023-03-30 11:00   ` Damien Le Moal
  0 siblings, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2023-03-30 11:00 UTC (permalink / raw)
  To: Chaitanya Kulkarni, Jiapeng Chong
  Cc: linux-scsi, target-devel, linux-kernel, Abaci Robot, martin.petersen

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-30 11:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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®