* [PATCH][linux-next] soc: fsl: dpio: Unsigned compared against 0 in qbman_swp_set_irq_coalescing()
@ 2021-10-18 16:05 Tim Gardner
2021-10-19 9:08 ` [PATCH][linux-next] soc: fsl: dpio: Unsigned compared against 0 in Ioana Ciornei
0 siblings, 1 reply; 2+ messages in thread
From: Tim Gardner @ 2021-10-18 16:05 UTC (permalink / raw)
To: linux-arm-kernel
Cc: tim.gardner, Roy Pledge, Li Yang, linux-kernel, linuxppc-dev
Coverity complains of unsigned compare against 0. There are 2 cases in
this function:
1821 itp = (irq_holdoff * 1000) / p->desc->qman_256_cycles_per_ns;
CID 121131 (#1 of 1): Unsigned compared against 0 (NO_EFFECT)
unsigned_compare: This less-than-zero comparison of an unsigned value is never true. itp < 0U.
1822 if (itp < 0 || itp > 4096) {
1823 max_holdoff = (p->desc->qman_256_cycles_per_ns * 4096) / 1000;
1824 pr_err("irq_holdoff must be between 0..%dus\n", max_holdoff);
1825 return -EINVAL;
1826 }
1827
unsigned_compare: This less-than-zero comparison of an unsigned value is never true. irq_threshold < 0U.
1828 if (irq_threshold >= p->dqrr.dqrr_size || irq_threshold < 0) {
1829 pr_err("irq_threshold must be between 0..%d\n",
1830 p->dqrr.dqrr_size - 1);
1831 return -EINVAL;
1832 }
Fix this by checking for 0. Also fix a minor comment typo.
Fixes ed1d2143fee53755ec601eb4d48a337a93933f71 ("soc: fsl: dpio: add support for
irq coalescing per software portal")
Cc: Roy Pledge <Roy.Pledge@nxp.com>
Cc: Li Yang <leoyang.li@nxp.com>
Cc: linux-kernel@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
I'm not 100% sure this is the right way to fix the warning, but according to the
pr_err() comments these values should never be 0.
---
drivers/soc/fsl/dpio/qbman-portal.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/soc/fsl/dpio/qbman-portal.c b/drivers/soc/fsl/dpio/qbman-portal.c
index d3c58df6240d..b768a14bb271 100644
--- a/drivers/soc/fsl/dpio/qbman-portal.c
+++ b/drivers/soc/fsl/dpio/qbman-portal.c
@@ -1816,16 +1816,16 @@ int qbman_swp_set_irq_coalescing(struct qbman_swp *p, u32 irq_threshold,
u32 itp, max_holdoff;
/* Convert irq_holdoff value from usecs to 256 QBMAN clock cycles
- * increments. This depends to the QBMAN internal frequency.
+ * increments. This depends on the QBMAN internal frequency.
*/
itp = (irq_holdoff * 1000) / p->desc->qman_256_cycles_per_ns;
- if (itp < 0 || itp > 4096) {
+ if (!itp || itp > 4096) {
max_holdoff = (p->desc->qman_256_cycles_per_ns * 4096) / 1000;
pr_err("irq_holdoff must be between 0..%dus\n", max_holdoff);
return -EINVAL;
}
- if (irq_threshold >= p->dqrr.dqrr_size || irq_threshold < 0) {
+ if (irq_threshold >= p->dqrr.dqrr_size || !irq_threshold) {
pr_err("irq_threshold must be between 0..%d\n",
p->dqrr.dqrr_size - 1);
return -EINVAL;
--
2.33.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][linux-next] soc: fsl: dpio: Unsigned compared against 0 in
2021-10-18 16:05 [PATCH][linux-next] soc: fsl: dpio: Unsigned compared against 0 in qbman_swp_set_irq_coalescing() Tim Gardner
@ 2021-10-19 9:08 ` Ioana Ciornei
0 siblings, 0 replies; 2+ messages in thread
From: Ioana Ciornei @ 2021-10-19 9:08 UTC (permalink / raw)
To: tim.gardner; +Cc: linux-arm-kernel, leoyang.li, linux-kernel, linuxppc-dev
>
> Subject: [PATCH][linux-next] soc: fsl: dpio: Unsigned compared against 0 in
>
> Coverity complains of unsigned compare against 0. There are 2 cases in
> this function:
>
> 1821 itp = (irq_holdoff * 1000) / p->desc->qman_256_cycles_per_ns;
>
> CID 121131 (#1 of 1): Unsigned compared against 0 (NO_EFFECT)
> unsigned_compare: This less-than-zero comparison of an unsigned value is never true. itp < 0U.
> 1822 if (itp < 0 || itp > 4096) {
> 1823 max_holdoff = (p->desc->qman_256_cycles_per_ns * 4096) / 1000;
> 1824 pr_err("irq_holdoff must be between 0..%dus\n", max_holdoff);
> 1825 return -EINVAL;
> 1826 }
> 1827
> unsigned_compare: This less-than-zero comparison of an unsigned value is never true. irq_threshold < 0U.
> 1828 if (irq_threshold >= p->dqrr.dqrr_size || irq_threshold < 0) {
> 1829 pr_err("irq_threshold must be between 0..%d\n",
> 1830 p->dqrr.dqrr_size - 1);
> 1831 return -EINVAL;
> 1832 }
>
> Fix this by checking for 0. Also fix a minor comment typo.
>
> Fixes ed1d2143fee53755ec601eb4d48a337a93933f71 ("soc: fsl: dpio: add support for
> irq coalescing per software portal")
I think this should be formatted as following:
Fixes: ed1d2143fee5 ("soc: fsl: dpio: add support for irq coalescing per software portal")
>
> Cc: Roy Pledge <Roy.Pledge@nxp.com>
> Cc: Li Yang <leoyang.li@nxp.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-arm-kernel@lists.infradead.org
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> ---
>
> I'm not 100% sure this is the right way to fix the warning, but according to the
> pr_err() comments these values should never be 0.
These threshold values can be 0, the pr_err comment tries to say that those are
the ranges, 0 and the maximum included.
>
> ---
> drivers/soc/fsl/dpio/qbman-portal.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/soc/fsl/dpio/qbman-portal.c b/drivers/soc/fsl/dpio/qbman-portal.c
> index d3c58df6240d..b768a14bb271 100644
> --- a/drivers/soc/fsl/dpio/qbman-portal.c
> +++ b/drivers/soc/fsl/dpio/qbman-portal.c
> @@ -1816,16 +1816,16 @@ int qbman_swp_set_irq_coalescing(struct qbman_swp *p, u32 irq_threshold,
> u32 itp, max_holdoff;
>
> /* Convert irq_holdoff value from usecs to 256 QBMAN clock cycles
> - * increments. This depends to the QBMAN internal frequency.
> + * increments. This depends on the QBMAN internal frequency.
> */
> itp = (irq_holdoff * 1000) / p->desc->qman_256_cycles_per_ns;
> - if (itp < 0 || itp > 4096) {
> + if (!itp || itp > 4096) {
> max_holdoff = (p->desc->qman_256_cycles_per_ns * 4096) / 1000;
> pr_err("irq_holdoff must be between 0..%dus\n", max_holdoff);
> return -EINVAL;
> }
>
> - if (irq_threshold >= p->dqrr.dqrr_size || irq_threshold < 0) {
> + if (irq_threshold >= p->dqrr.dqrr_size || !irq_threshold) {
> pr_err("irq_threshold must be between 0..%d\n",
> p->dqrr.dqrr_size - 1);
> return -EINVAL;
>
These 'value < 0' checks should be removed all together. Somehow I missed that
those are unsigned values.
Anyhow, thanks a lot that you spotted this.
Could you please sent the v2 towards the net-next tree since that's the tree
that adds the fixed patch?
Thanks.
-Ioana
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-19 9:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 16:05 [PATCH][linux-next] soc: fsl: dpio: Unsigned compared against 0 in qbman_swp_set_irq_coalescing() Tim Gardner
2021-10-19 9:08 ` [PATCH][linux-next] soc: fsl: dpio: Unsigned compared against 0 in Ioana Ciornei
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 NNTP newsgroup(s).