NVDIMM Device and Persistent Memory development
 help / color / mirror / Atom feed
From: jmoyer@redhat.com
To: nvdimm@lists.linux.dev
Cc: vishal.l.verma@intel.com, Jeff Moyer <jmoyer@redhat.com>
Subject: [PATCH ndctl 2/2] libndctl.c: major and minor numbers are unsigned
Date: Fri,  3 May 2024 16:54:56 -0400	[thread overview]
Message-ID: <20240503205456.80004-3-jmoyer@redhat.com> (raw)
In-Reply-To: <20240503205456.80004-1-jmoyer@redhat.com>

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(-)

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);
 }
-- 
2.43.0


  parent reply	other threads:[~2024-05-03 20:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 20:54 [PATCH ndctl 0/2] fix errors pointed out by static analysis jmoyer
2024-05-03 20:54 ` [PATCH ndctl 1/2] ndctl/keys.c: don't leak fd in error cases jmoyer
2024-05-06 19:11   ` Verma, Vishal L
2024-05-03 20:54 ` jmoyer [this message]
2024-05-06 19:11   ` [PATCH ndctl 2/2] libndctl.c: major and minor numbers are unsigned Verma, Vishal L

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=20240503205456.80004-3-jmoyer@redhat.com \
    --to=jmoyer@redhat.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /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).