Variable loopdiv can be assigned 0, then it is used as a denominator,
without checking it for 0.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 713d54a8bd81 ("[media] DiB7090: add support for the dib7090 based")
Signed-off-by: Daniil Dulov <[email protected]>
---
drivers/media/dvb-frontends/dib7000p.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/dib7000p.c b/drivers/media/dvb-frontends/dib7000p.c
index 55bee50aa871..bea5717907e7 100644
--- a/drivers/media/dvb-frontends/dib7000p.c
+++ b/drivers/media/dvb-frontends/dib7000p.c
@@ -497,7 +497,7 @@ static int dib7000p_update_pll(struct dvb_frontend *fe, struct dibx000_bandwidth
prediv = reg_1856 & 0x3f;
loopdiv = (reg_1856 >> 6) & 0x3f;
- if ((bw != NULL) && (bw->pll_prediv != prediv || bw->pll_ratio != loopdiv)) {
+ if (loopdiv && (bw != NULL) && (bw->pll_prediv != prediv || bw->pll_ratio != loopdiv)) {
dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)\n", prediv, bw->pll_prediv, loopdiv, bw->pll_ratio);
reg_1856 &= 0xf000;
reg_1857 = dib7000p_read_word(state, 1857);
--
2.25.1
Hi Daniil,
On Fri, Mar 24, 2023 at 06:12:09AM -0700, Daniil Dulov wrote:
> Variable loopdiv can be assigned 0, then it is used as a denominator,
> without checking it for 0.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 713d54a8bd81 ("[media] DiB7090: add support for the dib7090 based")
> Signed-off-by: Daniil Dulov <[email protected]>
> ---
> drivers/media/dvb-frontends/dib7000p.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/dvb-frontends/dib7000p.c b/drivers/media/dvb-frontends/dib7000p.c
> index 55bee50aa871..bea5717907e7 100644
> --- a/drivers/media/dvb-frontends/dib7000p.c
> +++ b/drivers/media/dvb-frontends/dib7000p.c
> @@ -497,7 +497,7 @@ static int dib7000p_update_pll(struct dvb_frontend *fe, struct dibx000_bandwidth
> prediv = reg_1856 & 0x3f;
> loopdiv = (reg_1856 >> 6) & 0x3f;
>
> - if ((bw != NULL) && (bw->pll_prediv != prediv || bw->pll_ratio != loopdiv)) {
> + if (loopdiv && (bw != NULL) && (bw->pll_prediv != prediv || bw->pll_ratio != loopdiv)) {
> dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)\n", prediv, bw->pll_prediv, loopdiv, bw->pll_ratio);
> reg_1856 &= 0xf000;
> reg_1857 = dib7000p_read_word(state, 1857);
> --
> 2.25.1
>
Did you send this patch to the correct recipients and mailing lists?
$ ./scripts/get_maintainer.pl drivers/media/dvb-frontends/dib7000p.c
Mauro Carvalho Chehab <[email protected]> (maintainer:MEDIA INPUT INFRASTRUCTURE (V4L/DVB))
[email protected] (open list:MEDIA INPUT INFRASTRUCTURE (V4L/DVB))
[email protected] (open list)
Hello Vladimir,
Sorry, I used a script with a wrong module, my fault.
-----Original Message-----
From: Vladimir Oltean [mailto:[email protected]]
Sent: Friday, March 24, 2023 4:15 PM
To: Daniil Dulov <[email protected]>
Cc: Andrew Lunn <[email protected]>; Vivien Didelot <[email protected]>; Florian Fainelli <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; Kurt Kanzenbach <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] media: dib7000p: Fix potential division by zero
Hi Daniil,
On Fri, Mar 24, 2023 at 06:12:09AM -0700, Daniil Dulov wrote:
> Variable loopdiv can be assigned 0, then it is used as a denominator,
> without checking it for 0.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 713d54a8bd81 ("[media] DiB7090: add support for the dib7090
> based")
> Signed-off-by: Daniil Dulov <[email protected]>
> ---
> drivers/media/dvb-frontends/dib7000p.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/dvb-frontends/dib7000p.c
> b/drivers/media/dvb-frontends/dib7000p.c
> index 55bee50aa871..bea5717907e7 100644
> --- a/drivers/media/dvb-frontends/dib7000p.c
> +++ b/drivers/media/dvb-frontends/dib7000p.c
> @@ -497,7 +497,7 @@ static int dib7000p_update_pll(struct dvb_frontend *fe, struct dibx000_bandwidth
> prediv = reg_1856 & 0x3f;
> loopdiv = (reg_1856 >> 6) & 0x3f;
>
> - if ((bw != NULL) && (bw->pll_prediv != prediv || bw->pll_ratio != loopdiv)) {
> + if (loopdiv && (bw != NULL) && (bw->pll_prediv != prediv ||
> +bw->pll_ratio != loopdiv)) {
> dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)\n", prediv, bw->pll_prediv, loopdiv, bw->pll_ratio);
> reg_1856 &= 0xf000;
> reg_1857 = dib7000p_read_word(state, 1857);
> --
> 2.25.1
>
Did you send this patch to the correct recipients and mailing lists?
$ ./scripts/get_maintainer.pl drivers/media/dvb-frontends/dib7000p.c
Mauro Carvalho Chehab <[email protected]> (maintainer:MEDIA INPUT INFRASTRUCTURE (V4L/DVB))
[email protected] (open list:MEDIA INPUT INFRASTRUCTURE (V4L/DVB))
[email protected] (open list)
On Fri, 24 Mar 2023 13:26:13 +0000 Daniil Dulov wrote:
> Sorry, I used a script with a wrong module, my fault.
Always run the script on the patch itself, not on a file path.