diff mbox series

[ndctl,2/2] libndctl.c: major and minor numbers are unsigned

Message ID 20240503205456.80004-3-jmoyer@redhat.com (mailing list archive)
State New, archived
Headers show
Series fix errors pointed out by static analysis | expand

Commit Message

Jeff Moyer May 3, 2024, 8:54 p.m. UTC
From: Jeff Moyer <jmoyer@redhat.com>

Static analysis points out that the cast of bus->major and bus->minor
to a signed type in the call to parent_dev_path could result in a
negative number.  I sincerely doubt we'll see major and minor numbers
that large, but let's fix it.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
---
 ndctl/lib/libndctl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Verma, Vishal L May 6, 2024, 7:11 p.m. UTC | #1
On Fri, 2024-05-03 at 16:54 -0400, jmoyer@redhat.com wrote:
> From: Jeff Moyer <jmoyer@redhat.com>
> 
> Static analysis points out that the cast of bus->major and bus->minor
> to a signed type in the call to parent_dev_path could result in a
> negative number.  I sincerely doubt we'll see major and minor numbers
> that large, but let's fix it.
> 
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>

Looks good,
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>

> ---
>  ndctl/lib/libndctl.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index ddbdd9a..f75dbd4 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -710,11 +710,12 @@ NDCTL_EXPORT void ndctl_set_log_priority(struct
> ndctl_ctx *ctx, int priority)
>  	daxctl_set_log_priority(ctx->daxctl_ctx, priority);
>  }
>  
> -static char *__dev_path(char *type, int major, int minor, int
> parent)
> +static char *__dev_path(char *type, unsigned int major, unsigned int
> minor,
> +			int parent)
>  {
>  	char *path, *dev_path;
>  
> -	if (asprintf(&path, "/sys/dev/%s/%d:%d%s", type, major,
> minor,
> +	if (asprintf(&path, "/sys/dev/%s/%u:%u%s", type, major,
> minor,
>  				parent ? "/device" : "") < 0)
>  		return NULL;
>  
> @@ -723,7 +724,7 @@ static char *__dev_path(char *type, int major,
> int minor, int parent)
>  	return dev_path;
>  }
>  
> -static char *parent_dev_path(char *type, int major, int minor)
> +static char *parent_dev_path(char *type, unsigned int major,
> unsigned int minor)
>  {
>          return __dev_path(type, major, minor, 1);
>  }
diff mbox series

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ddbdd9a..f75dbd4 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -710,11 +710,12 @@  NDCTL_EXPORT void ndctl_set_log_priority(struct ndctl_ctx *ctx, int priority)
 	daxctl_set_log_priority(ctx->daxctl_ctx, priority);
 }
 
-static char *__dev_path(char *type, int major, int minor, int parent)
+static char *__dev_path(char *type, unsigned int major, unsigned int minor,
+			int parent)
 {
 	char *path, *dev_path;
 
-	if (asprintf(&path, "/sys/dev/%s/%d:%d%s", type, major, minor,
+	if (asprintf(&path, "/sys/dev/%s/%u:%u%s", type, major, minor,
 				parent ? "/device" : "") < 0)
 		return NULL;
 
@@ -723,7 +724,7 @@  static char *__dev_path(char *type, int major, int minor, int parent)
 	return dev_path;
 }
 
-static char *parent_dev_path(char *type, int major, int minor)
+static char *parent_dev_path(char *type, unsigned int major, unsigned int minor)
 {
         return __dev_path(type, major, minor, 1);
 }