The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] staging: fsl-mc/dpio: Fix incorrect comparison
@ 2017-09-27 17:57 Ioana Radulescu
  2017-09-28 12:48 ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Ioana Radulescu @ 2017-09-27 17:57 UTC (permalink / raw)
  To: gregkh
  Cc: devel, linux-kernel, agraf, arnd, bogdan.purcareata, stuyoder,
	laurentiu.tudor, ruxandra.radulescu, roy.pledge

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

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

end of thread, other threads:[~2017-09-28 13:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-27 17:57 [PATCH] staging: fsl-mc/dpio: Fix incorrect comparison Ioana Radulescu
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox