* [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age
@ 2022-11-03 20:05 Larry Finger
2022-11-03 22:01 ` Philipp Hortmann
2022-11-03 23:08 ` Randy Dunlap
0 siblings, 2 replies; 4+ messages in thread
From: Larry Finger @ 2022-11-03 20:05 UTC (permalink / raw)
To: gregkh
Cc: phil, linux-staging, linux-kernel, linux-wireless, Larry Finger,
Randy Dunlap
When the configuration parameter CONFIG_HZ is less that 100, the compiler
generates an error as follows:
../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtl819x_translate_scan':
../drivers/staging/rtl8192e/rtllib_wx.c:220:57: warning: division by zero [-Wdiv-by-zero]
220 | (jiffies - network->last_scanned) / (HZ / 100));
| ^
In file included from ../include/linux/skbuff.h:45,
from ../include/linux/if_ether.h:19,
from ../include/linux/etherdevice.h:20,
from ../drivers/staging/rtl8192e/rtllib_wx.c:18:
../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtllib_wx_get_scan':
../drivers/staging/rtl8192e/rtllib_wx.c:261:70: warning: division by zero [-Wdiv-by-zero]
261 | (jiffies - network->last_scanned) /
|
In fact, is HZ is not a multiple of 100, the calculation will be wrong, but it
will compile correctly.
The fix is to get rid of the (HZ / 100) portion. To decrease any round-off
errors, the compiler is forced to perform the 100 * jiffies-difference before
dividing by HX. This patch is only compile tested.
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---
drivers/staging/rtl8192e/rtllib_wx.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
index da2c41c9b92f..7013425102dd 100644
--- a/drivers/staging/rtl8192e/rtllib_wx.c
+++ b/drivers/staging/rtl8192e/rtllib_wx.c
@@ -217,7 +217,7 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
p = custom;
p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom),
" Last beacon: %lums ago",
- (jiffies - network->last_scanned) / (HZ / 100));
+ (100 *(jiffies - network->last_scanned)) / HZ);
iwe.u.data.length = p - custom;
if (iwe.u.data.length)
start = iwe_stream_add_point_rsl(info, start, stop,
@@ -258,8 +258,8 @@ int rtllib_wx_get_scan(struct rtllib_device *ieee,
escape_essid(network->ssid,
network->ssid_len),
network->bssid,
- (jiffies - network->last_scanned) /
- (HZ / 100));
+ (100 * (jiffies - network->last_scanned)) /
+ HZ);
}
spin_unlock_irqrestore(&ieee->lock, flags);
--
2.38.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age
2022-11-03 20:05 [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age Larry Finger
@ 2022-11-03 22:01 ` Philipp Hortmann
2022-11-04 1:28 ` Larry Finger
2022-11-03 23:08 ` Randy Dunlap
1 sibling, 1 reply; 4+ messages in thread
From: Philipp Hortmann @ 2022-11-03 22:01 UTC (permalink / raw)
To: Larry Finger, gregkh
Cc: phil, linux-staging, linux-kernel, linux-wireless, Randy Dunlap
On 11/3/22 21:05, Larry Finger wrote:
> When the configuration parameter CONFIG_HZ is less that 100, the compiler
> generates an error as follows:
>
> ../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtl819x_translate_scan':
> ../drivers/staging/rtl8192e/rtllib_wx.c:220:57: warning: division by zero [-Wdiv-by-zero]
> 220 | (jiffies - network->last_scanned) / (HZ / 100));
> | ^
> In file included from ../include/linux/skbuff.h:45,
> from ../include/linux/if_ether.h:19,
> from ../include/linux/etherdevice.h:20,
> from ../drivers/staging/rtl8192e/rtllib_wx.c:18:
> ../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtllib_wx_get_scan':
> ../drivers/staging/rtl8192e/rtllib_wx.c:261:70: warning: division by zero [-Wdiv-by-zero]
> 261 | (jiffies - network->last_scanned) /
> |
>
> In fact, is HZ is not a multiple of 100, the calculation will be wrong, but it
> will compile correctly.
>
> The fix is to get rid of the (HZ / 100) portion. To decrease any round-off
> errors, the compiler is forced to perform the 100 * jiffies-difference before
> dividing by HX. This patch is only compile tested.
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
> ---
> drivers/staging/rtl8192e/rtllib_wx.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
> index da2c41c9b92f..7013425102dd 100644
> --- a/drivers/staging/rtl8192e/rtllib_wx.c
> +++ b/drivers/staging/rtl8192e/rtllib_wx.c
> @@ -217,7 +217,7 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> p = custom;
> p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom),
> " Last beacon: %lums ago",
> - (jiffies - network->last_scanned) / (HZ / 100));
> + (100 *(jiffies - network->last_scanned)) / HZ);
> iwe.u.data.length = p - custom;
> if (iwe.u.data.length)
> start = iwe_stream_add_point_rsl(info, start, stop,
> @@ -258,8 +258,8 @@ int rtllib_wx_get_scan(struct rtllib_device *ieee,
> escape_essid(network->ssid,
> network->ssid_len),
> network->bssid,
> - (jiffies - network->last_scanned) /
> - (HZ / 100));
> + (100 * (jiffies - network->last_scanned)) /
> + HZ);
> }
>
> spin_unlock_irqrestore(&ieee->lock, flags);
Line length of the description is to long.
Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age
2022-11-03 20:05 [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age Larry Finger
2022-11-03 22:01 ` Philipp Hortmann
@ 2022-11-03 23:08 ` Randy Dunlap
1 sibling, 0 replies; 4+ messages in thread
From: Randy Dunlap @ 2022-11-03 23:08 UTC (permalink / raw)
To: Larry Finger, gregkh; +Cc: phil, linux-staging, linux-kernel, linux-wireless
On 11/3/22 13:05, Larry Finger wrote:
> When the configuration parameter CONFIG_HZ is less that 100, the compiler
> generates an error as follows:
>
> ../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtl819x_translate_scan':
> ../drivers/staging/rtl8192e/rtllib_wx.c:220:57: warning: division by zero [-Wdiv-by-zero]
> 220 | (jiffies - network->last_scanned) / (HZ / 100));
> | ^
> In file included from ../include/linux/skbuff.h:45,
> from ../include/linux/if_ether.h:19,
> from ../include/linux/etherdevice.h:20,
> from ../drivers/staging/rtl8192e/rtllib_wx.c:18:
> ../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtllib_wx_get_scan':
> ../drivers/staging/rtl8192e/rtllib_wx.c:261:70: warning: division by zero [-Wdiv-by-zero]
> 261 | (jiffies - network->last_scanned) /
> |
>
> In fact, is HZ is not a multiple of 100, the calculation will be wrong, but it
> will compile correctly.
>
> The fix is to get rid of the (HZ / 100) portion. To decrease any round-off
> errors, the compiler is forced to perform the 100 * jiffies-difference before
> dividing by HX. This patch is only compile tested.
HZ.
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Thanks.
> ---
> drivers/staging/rtl8192e/rtllib_wx.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
> index da2c41c9b92f..7013425102dd 100644
> --- a/drivers/staging/rtl8192e/rtllib_wx.c
> +++ b/drivers/staging/rtl8192e/rtllib_wx.c
> @@ -217,7 +217,7 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> p = custom;
> p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom),
> " Last beacon: %lums ago",
> - (jiffies - network->last_scanned) / (HZ / 100));
> + (100 *(jiffies - network->last_scanned)) / HZ);
(100 * (jiffies ...
> iwe.u.data.length = p - custom;
> if (iwe.u.data.length)
> start = iwe_stream_add_point_rsl(info, start, stop,
> @@ -258,8 +258,8 @@ int rtllib_wx_get_scan(struct rtllib_device *ieee,
> escape_essid(network->ssid,
> network->ssid_len),
> network->bssid,
> - (jiffies - network->last_scanned) /
> - (HZ / 100));
> + (100 * (jiffies - network->last_scanned)) /
> + HZ);
> }
>
> spin_unlock_irqrestore(&ieee->lock, flags);
--
~Randy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age
2022-11-03 22:01 ` Philipp Hortmann
@ 2022-11-04 1:28 ` Larry Finger
0 siblings, 0 replies; 4+ messages in thread
From: Larry Finger @ 2022-11-04 1:28 UTC (permalink / raw)
To: Philipp Hortmann, gregkh
Cc: phil, linux-staging, linux-kernel, linux-wireless, Randy Dunlap
On 11/3/22 17:01, Philipp Hortmann wrote:
> On 11/3/22 21:05, Larry Finger wrote:
>> When the configuration parameter CONFIG_HZ is less that 100, the compiler
>> generates an error as follows:
>>
>> ../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtl819x_translate_scan':
>> ../drivers/staging/rtl8192e/rtllib_wx.c:220:57: warning: division by zero
>> [-Wdiv-by-zero]
>> 220 | (jiffies - network->last_scanned) / (HZ / 100));
>> | ^
>> In file included from ../include/linux/skbuff.h:45,
>> from ../include/linux/if_ether.h:19,
>> from ../include/linux/etherdevice.h:20,
>> from ../drivers/staging/rtl8192e/rtllib_wx.c:18:
>> ../drivers/staging/rtl8192e/rtllib_wx.c: In function 'rtllib_wx_get_scan':
>> ../drivers/staging/rtl8192e/rtllib_wx.c:261:70: warning: division by zero
>> [-Wdiv-by-zero]
>> 261 | (jiffies - network->last_scanned) /
>> |
>>
>> In fact, is HZ is not a multiple of 100, the calculation will be wrong, but it
>> will compile correctly.
>>
>> The fix is to get rid of the (HZ / 100) portion. To decrease any round-off
>> errors, the compiler is forced to perform the 100 * jiffies-difference before
>> dividing by HX. This patch is only compile tested.
>>
>> Reported-by: Randy Dunlap <rdunlap@infradead.org>
>> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
>> ---
>> drivers/staging/rtl8192e/rtllib_wx.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/staging/rtl8192e/rtllib_wx.c
>> b/drivers/staging/rtl8192e/rtllib_wx.c
>> index da2c41c9b92f..7013425102dd 100644
>> --- a/drivers/staging/rtl8192e/rtllib_wx.c
>> +++ b/drivers/staging/rtl8192e/rtllib_wx.c
>> @@ -217,7 +217,7 @@ static inline char *rtl819x_translate_scan(struct
>> rtllib_device *ieee,
>> p = custom;
>> p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom),
>> " Last beacon: %lums ago",
>> - (jiffies - network->last_scanned) / (HZ / 100));
>> + (100 *(jiffies - network->last_scanned)) / HZ);
>> iwe.u.data.length = p - custom;
>> if (iwe.u.data.length)
>> start = iwe_stream_add_point_rsl(info, start, stop,
>> @@ -258,8 +258,8 @@ int rtllib_wx_get_scan(struct rtllib_device *ieee,
>> escape_essid(network->ssid,
>> network->ssid_len),
>> network->bssid,
>> - (jiffies - network->last_scanned) /
>> - (HZ / 100));
>> + (100 * (jiffies - network->last_scanned)) /
>> + HZ);
>> }
>> spin_unlock_irqrestore(&ieee->lock, flags);
>
> Line length of the description is to long.
Addressed in v2.
Larry
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-04 1:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 20:05 [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age Larry Finger
2022-11-03 22:01 ` Philipp Hortmann
2022-11-04 1:28 ` Larry Finger
2022-11-03 23:08 ` Randy Dunlap
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.