ssb-main: Fix division by zero in ssb_calc_clock_rate()
PATCH 1/1 ssb-main: Fix division by zero in ssb_calc_clock_rate()
In ssb_calc_clock_rate(), the value of m1 may be zero because it is initialized using clkfactor_f6_resolv(). This function could return zero, so there is a possibility of dividing by zero, we fixed it by checking the values before dividing.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/ssb/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/ssb/main.c +12 -4
@@ -903,13 +903,21 @@ u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)case SSB_CHIPCO_CLK_MC_BYPASS :return clock;case SSB_CHIPCO_CLK_MC_M1 : -return (clock / m1); +if (m1 !=0 ) +return (clock / m1); +break ;case SSB_CHIPCO_CLK_MC_M1M2 : -return (clock / (m1 * m2)); +if ((m1 * m2) !=0 ) +return (clock / (m1 * m2)); +break ;case SSB_CHIPCO_CLK_MC_M1M2M3 : -return (clock / (m1 * m2 * m3)); +if ((m1 * m2 * m3) !=0 ) +return (clock / (m1 * m2 * m3)); +break ;case SSB_CHIPCO_CLK_MC_M1M3 : -return (clock / (m1 * m3)); +if ((m1 * m3) !=0 ) +return (clock / (m1 * m3)); +break ; }return 0 ;case SSB_PLLTYPE_2 :
Signature · 1 line
2.34.1
Quoted 43 lines · Rand Deeb
In
ssb_calc_clock_rate(), the value of m1 may be zero because it is initialized usingclkfactor_f6_resolv(). This function could return zero, so there is a possibility of dividing by zero, we fixed it by checking the values before dividing.Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by Rand Deeb <[email protected]>--- drivers/ssb/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/ssb/main.c +12
-5@@ -903,13 +903,21 @@ u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)case SSB_CHIPCO_CLK_MC_BYPASS :return clock;case SSB_CHIPCO_CLK_MC_M1 : -return (clock / m1); + if +return (clock / m1); +break ;case SSB_CHIPCO_CLK_MC_M1M2 : -return (clock / (m1 * m2)); + if ((m1 * m2) !=3D 0) +return (clock / (m1 * m2)); +break ;case SSB_CHIPCO_CLK_MC_M1M2M3 : -return (clock / (m1 * m2 * m3)); + if ((m1 * m2 * m3) !=3D 0) +return (clock / (m1 * m2 * m3)); +break ;case SSB_CHIPCO_CLK_MC_M1M3 : -return (clock / (m1 * m3)); + if ((m1 * m3) !=3D 0) +return (clock / (m1 * m3)); +break ; }return 0 ;case SSB_PLLTYPE_2 : --=20
Quoted 1 line
2.34.1
Rand,
I agree that clkfactor_f6_resolv() could return 0, but we have not been overrun with reports of divide by zero errors, which suggests that the branch is never taken. This patch will make your tool happy and is much simpler:
drivers/ssb/main.c +1 -1
@@ -837,7 +837,7 @@ static u32 clkfactor_f6_resolve(u32 v)case SSB_CHIPCO_CLK_F6_7 :return 7 ; } -return 0 ; +return 1 ; }/* Calculate the speed the backplane would run at a given set of clockcontrol
values */
Your patch has some technical problems as well. The subject should be "ssb: Fix division ..." In addition, note that all your if statements have an extraneous "3D" as in "(m1 !=3D 0)". To me, that indicates that your mailer is not sending plain text.
Larry
Michael Büsch
maintainerQuoted 10 lines · On Wed, 30 Aug 2023 14:50:42 -0500 Larry Finger <[email protected]>…
I agree that
clkfactor_f6_resolv()could return 0, but we have not been overrun with reports of divide by zero errors, which suggests that the branch is never taken. This patch will make your tool happy and is much simpler:drivers/ssb/main.c +0
-0
drivers/ssb/main.c static u32 clkfactor_f6_resolve(u32 v) · line 841
Quoted 6 lines
drivers/ssb/main.c +1
-1@@ -837,7 +837,7 @@ static u32 clkfactor_f6_resolve(u32 v)case SSB_CHIPCO_CLK_F6_7 :return 7 ; } -return 0 ; +return 1 ; }
Yes, I agree that this is the much simpler and also more sensible solution to this theoretical problem.
Signature · 2 lines
Michael Büsch https://bues.ch/
Dear Larry,
1- Yes, I agree that your solution is simpler, and I thought about it, but I thought that the one who set the value zero put it for some reason, so I did not want to change it.
2- It's first time to send using this mailer, but we tested it by sending the patch to our personal emails (gmail, etc..) and it works perfectly! I don't know why this encryption appears only when we get a response from you, but we're still investigating. We will fix it, and follow all the recommendations in the future.
Thanks for your cooperation.
Best regards,
Rand
----- Original Message -----
From: "Larry Finger" <[email protected]>
To: "Rand Deeb" <[email protected]>, "Michael Buesch" <[email protected]>, [email protected], [email protected]
Cc: [email protected], "Воскресенский Станислав Игоревич" <[email protected]>
Sent: Wednesday, August 30, 2023 10:50:42 PM
Subject: Re: [PATCH] ssb-main: Fix division by zero in ssb_calc_clock_rate()
Quoted 43 lines · Rand Deeb
In
ssb_calc_clock_rate(), the value of m1 may be zero because it is initialized usingclkfactor_f6_resolv(). This function could return zero, so there is a possibility of dividing by zero, we fixed it by checking the values before dividing.Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by Rand Deeb <[email protected]>--- drivers/ssb/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/ssb/main.c +12
-5@@ -903,13 +903,21 @@ u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)case SSB_CHIPCO_CLK_MC_BYPASS :return clock;case SSB_CHIPCO_CLK_MC_M1 : -return (clock / m1); + if +return (clock / m1); +break ;case SSB_CHIPCO_CLK_MC_M1M2 : -return (clock / (m1 * m2)); + if ((m1 * m2) !=3D 0) +return (clock / (m1 * m2)); +break ;case SSB_CHIPCO_CLK_MC_M1M2M3 : -return (clock / (m1 * m2 * m3)); + if ((m1 * m2 * m3) !=3D 0) +return (clock / (m1 * m2 * m3)); +break ;case SSB_CHIPCO_CLK_MC_M1M3 : -return (clock / (m1 * m3)); + if ((m1 * m3) !=3D 0) +return (clock / (m1 * m3)); +break ; }return 0 ;case SSB_PLLTYPE_2 : --=20
Quoted 1 line
2.34.1
Rand,
I agree that clkfactor_f6_resolv() could return 0, but we have not been overrun with reports of divide by zero errors, which suggests that the branch is never taken. This patch will make your tool happy and is much simpler:
drivers/ssb/main.c +1 -1
@@ -837,7 +837,7 @@ static u32 clkfactor_f6_resolve(u32 v)case SSB_CHIPCO_CLK_F6_7 :return 7 ; } -return 0 ; +return 1 ; }/* Calculate the speed the backplane would run at a given set of clockcontrol
values */
Your patch has some technical problems as well. The subject should be "ssb: Fix division ..." In addition, note that all your if statements have an extraneous "3D" as in "(m1 !=3D 0)". To me, that indicates that your mailer is not sending plain text.
Larry
Quoted 5 lines · Ранд Дееб
Dear Larry,
1- Yes, I agree that your solution is simpler, and I thought about it, but I thought that the one who set the value zero put it for some reason, so I did not want to change it.
Don't top -pots.
Quoted 2 lines
2- It's first time to send using this mailer, but we tested it by sending the patch to our personal emails (gmail, etc..) and it works perfectly! I
Really? No, it does not work perfectly. Look at your email - you send it non-standard way.
Quoted 3 lines
don't know why this encryption appears only when we get a response from you, but we're still investigating. We will fix it, and follow all the recommendations in the future.
What encryption? You mean encoding? Encryption is something entirely else and if you enable PGP or whatever, you must disable it. It's public work.
Best regards,
Krzysztof
Quoted 19 lines · ----- On Aug 31, 2023, at 4:46 PM, Krzysztof Kozlowski [email protected] wrote:
Quoted 5 lines · Ранд Дееб
Dear Larry,
1- Yes, I agree that your solution is simpler, and I thought about it, but I thought that the one who set the value zero put it for some reason, so I did not want to change it.
Don't top -pots.
Quoted 2 lines
2- It's first time to send using this mailer, but we tested it by sending the patch to our personal emails (gmail, etc..) and it works perfectly! I
Really? No, it does not work perfectly. Look at your email - you send it non-standard way.
Quoted 3 lines
don't know why this encryption appears only when we get a response from you, but we're still investigating. We will fix it, and follow all the recommendations in the future.
Quoted 6 lines
What encryption? You mean encoding? Encryption is something entirely else and if you enable PGP or whatever, you must disable it. It's public work.
Best regards,
Krzysztof
Dear Krzysztof,
Thank you again for your professionalism, cooperation and recommendations, we appreciate it. I understand what you're saying, after I looked at the information in the link:
https://lore.kernel.org/all/[email protected]/raw
But what I am saying is that I sent the patch myself (gmail) and there was no encoding ! screenshot in the attachments !!
Anyway we will try to fix everything next time.
Regarding the ecoding/ecryption, I apologize, of course I know the difference, but it was a translator mistake, knowing that I do not usually use it, but for certain reasons I used it this time, I will be more careful next time.
"I hope this message will not be top-post"
Best regards,
Rand
Michael Büsch
maintainerQuoted 3 lines · On Thu, 31 Aug 2023 10:07:33 +0300 (MSK) Ранд Дееб <[email protected]>…
1- Yes, I agree that your solution is simpler, and I thought about it, but I thought that the one who set the value zero put it for some reason, so I did not want to change it.
Yes, I understand your reasoning and I had the same thought initially. But I looked into the code and I am pretty sure that there is no reason for the default case returning 0.
In fact, I think returning a 1 as default makes much more sense as the default value for a factor.
Changing this from 0 to 1 will get my ack.
Signature · 2 lines
Michael Büsch https://bues.ch/
Quoted 8 lines · Michael Büsch
Quoted 3 lines · On Thu, 31 Aug 2023 10:07:33 +0300 (MSK) Ранд Дееб <[email protected]>…
1- Yes, I agree that your solution is simpler, and I thought about it, but I thought that the one who set the value zero put it for some reason, so I did not want to change it.
Quoted 7 lines
Yes, I understand your reasoning and I had the same thought initially. But I looked into the code and I am pretty sure that there is no reason for the default case returning 0.
In fact, I think returning a 1 as default makes much more sense as the default value for a factor.Changing this from 0 to 1 will get my ack.
As far as I can tell, that return 0 is there only to silence the compiler as the switch statement has no default. As I said earlier, there have been no reports of divide by zero entries in this ancient driver, thus the value returned is not relevant. As a static tool sees the possibility of a returned zero leading to a potential divide by zero, making it a one it the only thing that makes sense.
I have no idea why this part of the patch has led to so much discussion!
Larry
Quoted 8 lines · Larry Finger
/* Calculate the speed the backplane would run at a given set of clockcontrol
values */Your patch has some technical problems as well. The subject should be "ssb: Fix division ..." In addition, note that all your if statements have an extraneous "3D" as in "(m1 !=3D 0)". To me, that indicates that your mailer is not sending plain text.
It's sending everything as quoted-printable. Nothing improved here from their previous version.
Best regards,
Krzysztof
Quoted 6 lines · Rand Deeb
In
ssb_calc_clock_rate(), the value of m1 may be zero because it is initialized usingclkfactor_f6_resolv(). This function could return zero, so there is a possibility of dividing by zero, we fixed it by checking the values before dividing.Found by Linux Verification Center (linuxtesting.org) with SVACE.
Version your patches and provide changelog after --- .
Quoted 11 lines
Signed-off-by Rand Deeb <[email protected]>--- drivers/ssb/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/ssb/main.c +0
-0
drivers/ssb/main.c u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m) · line 906
Quoted 5 lines
drivers/ssb/main.c +1
-1@@ -903,13 +903,21 @@ u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)case SSB_CHIPCO_CLK_MC_BYPASS :return clock;case SSB_CHIPCO_CLK_MC_M1 : -return (clock / m1); + if (m1 !=3D 0)
Nothing improved here.
Don't send patches as quoted-printable via some weird mailers. Recommendation is to use standard tool - git send-email.
As you can easily see on the web - it is re-formatted for quoted-printable:
https://lore.kernel.org/all/[email protected]/raw
Best regards,
Krzysztof
Dear Krzysztof,
Thank you for your response, now I see, but we already used the standard tool git send-email to send the patch. It seems we have to set the transfer-encoding manually (not default), we will fix it next time. It's our first time trying to send a patch.
Best Regards,
Rand
----- Original Message -----
From: "Krzysztof Kozlowski" <[email protected]>
To: "Rand Deeb" <[email protected]>, "Michael Buesch" <[email protected]>, "linux-wireless" <[email protected]>, "linux-kernel" <[email protected]>
Cc: "lvc-project" <[email protected]>, "Воскресенский Станислав Игоревич" <[email protected]>
Sent: Thursday, August 31, 2023 4:45:15 PM
Subject: Re: [PATCH] ssb-main: Fix division by zero in ssb_calc_clock_rate()
Quoted 6 lines · Rand Deeb
In
ssb_calc_clock_rate(), the value of m1 may be zero because it is initialized usingclkfactor_f6_resolv(). This function could return zero, so there is a possibility of dividing by zero, we fixed it by checking the values before dividing.Found by Linux Verification Center (linuxtesting.org) with SVACE.
Version your patches and provide changelog after --- .
Quoted 11 lines
Signed-off-by Rand Deeb <[email protected]>--- drivers/ssb/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/ssb/main.c +0
-0
drivers/ssb/main.c u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m) · line 906
Quoted 5 lines
drivers/ssb/main.c +1
-1@@ -903,13 +903,21 @@ u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)case SSB_CHIPCO_CLK_MC_BYPASS :return clock;case SSB_CHIPCO_CLK_MC_M1 : -return (clock / m1); + if (m1 !=3D 0)
Nothing improved here.
Don't send patches as quoted-printable via some weird mailers. Recommendation is to use standard tool - git send-email.
As you can easily see on the web - it is re-formatted for quoted-printable:
https://lore.kernel.org/all/[email protected]/raw
Best regards,
Krzysztof
Quoted 7 lines · Ранд Дееб
Dear Krzysztof,
Thank you for your response, now I see, but we already used the standard tool git send-email to send the patch. It seems we have to set the transfer-encoding manually (not default), we will fix it next time. It's our first time trying to send a patch.
Again, do not top post.
If you used git send-email, then where is X-Mailer header saying it was git send-email? That's why I doubt you used it.
Best regards,
Krzysztof