diff mbox series

[ndctl,6/8] lib/inject: check whether cmd is created successfully

Message ID 8e8a88ee-a792-dc86-0fa7-b2609588fc88@huawei.com (mailing list archive)
State New, archived
Headers show
Series fix serverl issues reported by Coverity | expand

Commit Message

Zhiqiang Liu Nov. 6, 2020, 9:27 a.m. UTC
ndctl_bus_cmd_new_ars_cp() is called to create cmd,
which may return NULL. We need to check whether it
is NULL in callers, such as ndctl_namespace_get_clear_uint
and ndctl_namespace_injection_status.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
 ndctl/lib/inject.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Verma, Vishal L Dec. 17, 2020, 3:33 a.m. UTC | #1
On Fri, 2020-11-06 at 17:27 +0800, Zhiqiang Liu wrote:
> ndctl_bus_cmd_new_ars_cp() is called to create cmd,
> which may return NULL. We need to check whether it
> is NULL in callers, such as ndctl_namespace_get_clear_uint
> and ndctl_namespace_injection_status.
> 
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> ---
>  ndctl/lib/inject.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
> index 815f254..b543fc7 100644
> --- a/ndctl/lib/inject.c
> +++ b/ndctl/lib/inject.c
> @@ -114,6 +114,10 @@ static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns)
>  	if (rc)
>  		return rc;
>  	cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
> +	if (!cmd) {
> +		err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
> +		return -ENOTTY;
> +	}
>  	rc = ndctl_cmd_submit(cmd);
>  	if (rc < 0) {
>  		dbg(ctx, "Error submitting ars_cap: %d\n", rc);
> @@ -457,6 +461,10 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns)
>  			return rc;
> 
>  		cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
> +		if (!cmd) {
> +			err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
> +			return -ENOTTY;
> +		}
>  		rc = ndctl_cmd_submit(cmd);
>  		if (rc < 0) {
>  			dbg(ctx, "Error submitting ars_cap: %d\n", rc);

This looks good in general, but I made some small fixups while applying.
Printing the bus provider here isn't as useful - I replaced it with
printing the namespace 'devname':

-               err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
+               err(ctx, "%s: failed to create cmd\n",
+                       ndctl_namespace_get_devname(ndns));

Also fixed up a couple of typos in commit messages, but otherwise the
series looks good and I've applied it for v71.

Thanks,
-Vishal
Zhiqiang Liu Dec. 17, 2020, 6:19 a.m. UTC | #2
On 2020/12/17 11:33, Verma, Vishal L wrote:
> On Fri, 2020-11-06 at 17:27 +0800, Zhiqiang Liu wrote:
>> ndctl_bus_cmd_new_ars_cp() is called to create cmd,
>> which may return NULL. We need to check whether it
>> is NULL in callers, such as ndctl_namespace_get_clear_uint
>> and ndctl_namespace_injection_status.
>>
>> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>> ---
>>  ndctl/lib/inject.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
>> index 815f254..b543fc7 100644
>> --- a/ndctl/lib/inject.c
>> +++ b/ndctl/lib/inject.c
>> @@ -114,6 +114,10 @@ static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns)
>>  	if (rc)
>>  		return rc;
>>  	cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
>> +	if (!cmd) {
>> +		err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
>> +		return -ENOTTY;
>> +	}
>>  	rc = ndctl_cmd_submit(cmd);
>>  	if (rc < 0) {
>>  		dbg(ctx, "Error submitting ars_cap: %d\n", rc);
>> @@ -457,6 +461,10 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns)
>>  			return rc;
>>
>>  		cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
>> +		if (!cmd) {
>> +			err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
>> +			return -ENOTTY;
>> +		}
>>  		rc = ndctl_cmd_submit(cmd);
>>  		if (rc < 0) {
>>  			dbg(ctx, "Error submitting ars_cap: %d\n", rc);
> 
> This looks good in general, but I made some small fixups while applying.
> Printing the bus provider here isn't as useful - I replaced it with
> printing the namespace 'devname':
> 
> -               err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
> +               err(ctx, "%s: failed to create cmd\n",
> +                       ndctl_namespace_get_devname(ndns));
> 
> Also fixed up a couple of typos in commit messages, but otherwise the
> series looks good and I've applied it for v71.
> 

Thanks again.

Regards
Zhiqiang Liu

> Thanks,
> -Vishal
>
diff mbox series

Patch

diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
index 815f254..b543fc7 100644
--- a/ndctl/lib/inject.c
+++ b/ndctl/lib/inject.c
@@ -114,6 +114,10 @@  static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns)
 	if (rc)
 		return rc;
 	cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
+	if (!cmd) {
+		err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
+		return -ENOTTY;
+	}
 	rc = ndctl_cmd_submit(cmd);
 	if (rc < 0) {
 		dbg(ctx, "Error submitting ars_cap: %d\n", rc);
@@ -457,6 +461,10 @@  NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns)
 			return rc;

 		cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
+		if (!cmd) {
+			err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus));
+			return -ENOTTY;
+		}
 		rc = ndctl_cmd_submit(cmd);
 		if (rc < 0) {
 			dbg(ctx, "Error submitting ars_cap: %d\n", rc);