mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
To: <gregkh@linuxfoundation.org>
Cc: <devel@driverdev.osuosl.org>, <linux-kernel@vger.kernel.org>,
	<agraf@suse.de>, <arnd@arndb.de>, <bogdan.purcareata@nxp.com>,
	<stuyoder@gmail.com>, <laurentiu.tudor@nxp.com>,
	<ruxandra.radulescu@nxp.com>, <roy.pledge@nxp.com>
Subject: [PATCH] staging: fsl-mc/dpio: Fix incorrect comparison
Date: Wed, 27 Sep 2017 12:57:28 -0500	[thread overview]
Message-ID: <20170927175728.3307-1-ruxandra.radulescu@nxp.com> (raw)

For some dpio functions, a negative cpu id parameter value is
valid and means "any". But when trying to validate this param
value against an upper limit, in this case num_possible_cpus(),
we risk obtaining the wrong result due to an implicit cast
to unsigned.

Avoid an incorrect check result when cpu id is negative, by
explicitly stating the comparison is between signed values.

Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
---
 drivers/staging/fsl-mc/bus/dpio/dpio-service.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dpio/dpio-service.c b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
index f809682..26922fc 100644
--- a/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
+++ b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
@@ -76,7 +76,7 @@ static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d,
 	if (d)
 		return d;
 
-	if (unlikely(cpu >= num_possible_cpus()))
+	if (unlikely(cpu >= (int)num_possible_cpus()))
 		return NULL;
 
 	/*
@@ -121,7 +121,7 @@ struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
 		return NULL;
 
 	/* check if CPU is out of range (-1 means any cpu) */
-	if (desc->cpu >= num_possible_cpus()) {
+	if (desc->cpu >= (int)num_possible_cpus()) {
 		kfree(obj);
 		return NULL;
 	}
-- 
2.7.4

             reply	other threads:[~2017-09-27 17:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27 17:57 Ioana Radulescu [this message]
2017-09-28 12:48 ` Dan Carpenter
2017-09-28 12:53   ` Dan Carpenter
2017-09-28 13:07   ` Ruxandra Ioana Radulescu
2017-09-28 13:17     ` gregkh
2017-09-28 13:23       ` Ruxandra Ioana Radulescu

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=20170927175728.3307-1-ruxandra.radulescu@nxp.com \
    --to=ruxandra.radulescu@nxp.com \
    --cc=agraf@suse.de \
    --cc=arnd@arndb.de \
    --cc=bogdan.purcareata@nxp.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=laurentiu.tudor@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roy.pledge@nxp.com \
    --cc=stuyoder@gmail.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

all inboxes | Powered by JetHome®