Message ID | 20221103200507.14304-1-Larry.Finger@lwfinger.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp756158wru; Thu, 3 Nov 2022 13:35:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Lwg3DEndXBbtgOeYZBQ7I2F2y9mE2ns3ko3/X8A2P3f5EMGZ4t7sYLVMqHQrt7NoyOenJ X-Received: by 2002:a17:90b:524f:b0:212:c22f:fbd1 with SMTP id sh15-20020a17090b524f00b00212c22ffbd1mr33975526pjb.155.1667507723589; Thu, 03 Nov 2022 13:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667507723; cv=none; d=google.com; s=arc-20160816; b=sDHy1Ta3ic+lUK2Kcvmbre007W4wVv1Lhw9kZ16hmbRptY9MYuHlesQ0g8ZFt0qma2 oej7QwB23ggCdJqGPycKaAhRrPX6ArQ/cZBb3X1Q9jlQTf2LhGY0J+IjsA8t8cwHSXnd aAhMSho/vTNP507TmmZZ4LPmgFGwd62j8avmXWoWMi8AjrAJwzNFqsElFETsdgyk74Yq mxbaZWDcajvvetKemwaV5BCx5WubcarN+DQYgL8sQeU3osHVWAgE00xRDjg49qioe3sP Tl0K2v12xQDM969dlptKn9BpvLpFqToMDIF3pkGh4IX9FkTdIs2At+1v1M4v+OPBFrEW OG5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=QJqmk5I6DAgiLsobZTGa57P2bCxeBPQdNtIGsZHnmfo=; b=z7ULdvfVSOvwtJx/K0MQDdji4IcryrdQyc7R3pqpMUmkUXJD+3dhvqRv4fnhn3o+bT Y8Wk2fubYDOIbB6gqtROykA48+KJhxcDaIqtkBPsRGyO7QHspqUoa+To1xUG8Djablor 2N2yKDUvxcZz1+TGqrxj8RHRPJ2US1q8E66/sFnk1XilWCY63fp3UMmGY9mrzRilxKck yhUGedVpWKSiqPQCr2/g3wt2x35tuBbnviqPTlS36Jk29PM3tg6YjI8cQHlOxB/1FHWw 09LVsVoycLjFhUAdgr/cCVwXfTNq8zw0wsM0yDCF526K624iwlmQgxgR/9n4zvgZiFXv q6TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="fhg/fjhD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb18-20020a17090b281200b0020291c96b13si914705pjb.121.2022.11.03.13.34.56; Thu, 03 Nov 2022 13:35:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="fhg/fjhD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231588AbiKCUHU (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Thu, 3 Nov 2022 16:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231721AbiKCUGX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 3 Nov 2022 16:06:23 -0400 Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C57821824; Thu, 3 Nov 2022 13:05:19 -0700 (PDT) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-13bef14ea06so3471725fac.3; Thu, 03 Nov 2022 13:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=QJqmk5I6DAgiLsobZTGa57P2bCxeBPQdNtIGsZHnmfo=; b=fhg/fjhDvPlrIUzjSmWqpspjw+rGGlKIeolmzQWRiNGUdii5IMjJx1jz6sN1AVjccA Fo7mo3HkOMRJBFiWrECJYtfzGpBrvxUd+h02JAqrV6NEZdKghONQDyxTikE6kVCa56WD /E3tkjjQLUVBnzKmwBckmnzvpkiBJky00erYc0viedcQID+Ua/TvESwDB03S2ND8eF0O va8n8xHHuFuAntxHJRIAvhZla7bXk7z4i3Blaxbdja6qfkASmvnIolYyHYIdIC7HNXO9 JPB2c9y7idm53B5OFPBSVtFZ1CLAcTqSWtoONJSbqEFOBwVKURkyo33ndJLs3U2cnwKX 6pLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QJqmk5I6DAgiLsobZTGa57P2bCxeBPQdNtIGsZHnmfo=; b=f5PZ7DWquz/KTbe9Jdt8EsCe7FmxqqSGG+rJdZAJdUxhCteFuZFSO9mtrfiwfmSysV p1NBlcQieFqv6Q15yWIDRoBt5Ap17iul6X0h/Epm7RgWBJ8iW9E7UdOUQUJ3Y5458iyd HmKtr2VSm1BOUsSHLUZ6hpw1+jH3X4LY8zz0Kh2uO34S/nyj3ZkB0Rwjw97blcF/AjO+ LNORlNu9Xn7faYxpJWSA7uQ46cfq7gDf0Wp2TTlPKWr68sAJbpwyaEUBDdJV6tcQY+mf 70rc7EBa1q3W5G5oTFMeFc3yu6RCqwQnI+yA4BqgiEgiiBe0MGXiiEfL66l4wkacTouw 2UhA== X-Gm-Message-State: ACrzQf01g/idCz1flwbA5TF70r+obmpBQgkzbT1lXO5533+Qybwx5/mf CuO/TW/8JB7lD1R/x/i3w1kvkRubFls= X-Received: by 2002:a05:6871:891:b0:13b:86bc:7b51 with SMTP id r17-20020a056871089100b0013b86bc7b51mr19830284oaq.174.1667505918579; Thu, 03 Nov 2022 13:05:18 -0700 (PDT) Received: from localhost.localdomain ([216.130.59.33]) by smtp.gmail.com with ESMTPSA id r3-20020a056870e98300b0013bc40b09dasm842286oao.17.2022.11.03.13.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 13:05:18 -0700 (PDT) Sender: Larry Finger <larry.finger@gmail.com> From: Larry Finger <Larry.Finger@lwfinger.net> To: gregkh@linuxfoundation.org Cc: phil@philpotter.co.uk, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, Larry Finger <Larry.Finger@lwfinger.net>, Randy Dunlap <rdunlap@infradead.org> Subject: [PATCH] staging: rtl8192e: Fix divide fault when calculating beacon age Date: Thu, 3 Nov 2022 15:05:07 -0500 Message-Id: <20221103200507.14304-1-Larry.Finger@lwfinger.net> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748508578561836895?= X-GMAIL-MSGID: =?utf-8?q?1748508578561836895?= |
Series |
staging: rtl8192e: Fix divide fault when calculating beacon age
|
|
Commit Message
Larry Finger
Nov. 3, 2022, 8:05 p.m. UTC
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(-)
Comments
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>
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);
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
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);