Message ID | 20221104012750.2076-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 l7csp101412wru; Thu, 3 Nov 2022 18:30:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4B1gP5/Ras9zTg2VoLm2oHlOMIJYvkrhvXoI6FTlRSM3mkmHHpwI9XxhH5kFxEks4qmwPj X-Received: by 2002:a05:6402:3887:b0:458:289e:c9cc with SMTP id fd7-20020a056402388700b00458289ec9ccmr33408922edb.101.1667525432642; Thu, 03 Nov 2022 18:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667525432; cv=none; d=google.com; s=arc-20160816; b=sQnzbVnmMbJ9WWxOcBKbXB9pjvgyozwJxSFm3UDikY3sl5cljZj3Zn9yxcfl3m8kPS Jrz49d1iykBz+iSXT6iR3hwgau8zI974tmOasqcNnQiDxvJ5VefL5HTzCc+UaEtzPx29 xDrKE6jSc/aSXs3LvyqOLlHu09rNQJGYv9vHgPhl4dw2iyo649KwphZhk05M0Sw6NKjo dL6THPcxwR5BhgySH0oPOTPLS+EfjSYNN1IiAwf63LUMi8Oa59Slrml8nFXtG5SZmYDp JF0jB+/rt3bIncSbvKnG5uqNpGQV+g+YDiGDf99/6RTqtfnnqEmOmIzrSQOL55OusfFf COPQ== 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=aUilUaHJkRjMTuKpx9KuulcmPnQFwe0ZTOEMgpM9EUs=; b=uMCT4bRo3/CeDf7rqrgt75HCdxGB+FWajl1iu6gVjaTMAv6B0scAUtwJ5Mth+SwgB3 AmRXOzcbOlVvfBeli4uF5/T9rLI1f+9dlKSMAHM2FEaP4QmBzE2SHasTcItRhGD1Gm9E wWU6EEKNy8p0DPs2ZZ5eZ6wYTkPdHxuhP5vCX87yi2SGQL/vDLpnguBsI98FibE2ecN9 37EU4MylPoKJehX9MhLkGtcZQvikaqzvnUwVIhTbJ8ZwIAPQSbAWXxCe9FWAwkf3K7+p K7XiMOubY85DWPw9ByuFXUCOtU9gMEEKNVnjxDVnk74xBz6Z2MRNOK1GYFV3nfCGiYqm TLgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Qiuj1zxH; 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 cs15-20020a170906dc8f00b007ad9885d2b1si3580239ejc.301.2022.11.03.18.30.09; Thu, 03 Nov 2022 18:30:32 -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=Qiuj1zxH; 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 S230307AbiKDB2D (ORCPT <rfc822;jimliu8233@gmail.com> + 99 others); Thu, 3 Nov 2022 21:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiKDB16 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 3 Nov 2022 21:27:58 -0400 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5385423392; Thu, 3 Nov 2022 18:27:57 -0700 (PDT) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-12c8312131fso4172088fac.4; Thu, 03 Nov 2022 18:27:57 -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=aUilUaHJkRjMTuKpx9KuulcmPnQFwe0ZTOEMgpM9EUs=; b=Qiuj1zxH72t4rljyyB3fSEkfn0epewXXoN357R0R6Usp3EKlWrx8iU6hpHUzfKpX1N jWUvsrLP7T+/T1HTqFmsPXuwFA3OhGOVpq/6hknV2wHSHf8vxvD0SjqSU9ikQYMusbVh Ibvt/VUaZO27SjIcQQsqhhHansMDWkRhoZJ25wlaEJFLerIHLY9Z6gt6gBWracbEq52v WyLK4J9IOWlBKdFWafyeUCtKH3Grw4/GJa2RKMtb5uDabXtgzXtRP9PcMO11bAgO+rcE 8vVYN3Y5hRUttjbnXz/13kwYZdkqigq9lG1nsPlZIePUhTXp23fp7wrjIrx9Cim5/XWG SHNQ== 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=aUilUaHJkRjMTuKpx9KuulcmPnQFwe0ZTOEMgpM9EUs=; b=cFiQjEvUumk5ghW4GWmY+37rM48BwHcDg8M2BNAClxyUxVo3wjuXkw2x+MRS8bOKgD wUcOU/gKupzfEc9gaVEkEZ2nnw6vYJUHZq6PlMGI9vuwroVobBtl2FbH/Mu8uv9PGTe5 tnuv4rXrxOMezr/l1FtHTwZwr3wtcZqHv6OanqkyTC1N1VsVJhnoxY0nveJMnm2ZONZK zeoWl9WlLkdpoQWI0uH7E93yEcxScziMAz67+hgOyR+xfHVQFfUB8cV76AUPMe2VHTaD LqOBcFNpnBNpeWpN7YIMnCODbpdq79p6DH6VsfldU/mXGDZQEOgn/Ah5GbzNHUi3tA7K 9Row== X-Gm-Message-State: ACrzQf3FeyRszoUeUQ6DM8M0Zh/RidMcxTk8v5GBFLPUwffAfWQnoNQD 8lxaEga3lngW+qkMsECFl1U= X-Received: by 2002:a05:6870:3414:b0:13c:787e:15ba with SMTP id g20-20020a056870341400b0013c787e15bamr19114631oah.164.1667525276643; Thu, 03 Nov 2022 18:27:56 -0700 (PDT) Received: from localhost.localdomain ([216.130.59.33]) by smtp.gmail.com with ESMTPSA id b6-20020a9d6b86000000b0066c75a2643asm924675otq.66.2022.11.03.18.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 18:27:56 -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 v2] staging: rtl8192e: Fix divide fault when calculating beacon age Date: Thu, 3 Nov 2022 20:27:50 -0500 Message-Id: <20221104012750.2076-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?1748527147724865585?= X-GMAIL-MSGID: =?utf-8?q?1748527147724865585?= |
Series |
[v2] staging: rtl8192e: Fix divide fault when calculating beacon age
|
|
Commit Message
Larry Finger
Nov. 4, 2022, 1:27 a.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 HZ. This patch is only compile tested. Reported-by: Randy Dunlap <rdunlap@infradead.org> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> --- v2 - some commit log lines are shortened - add space after * operator --- drivers/staging/rtl8192e/rtllib_wx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On 11/4/22 02:27, 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 HZ. This patch is only compile tested. > > Reported-by: Randy Dunlap <rdunlap@infradead.org> > Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested > Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> > --- > v2 - some commit log lines are shortened > - add space after * operator > --- > 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..217426ee2e92 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); Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c index da2c41c9b92f..217426ee2e92 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);