From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752315AbdDGCg7 (ORCPT ); Thu, 6 Apr 2017 22:36:59 -0400 Received: from smtprelay0017.hostedemail.com ([216.40.44.17]:60422 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751884AbdDGCgz (ORCPT ); Thu, 6 Apr 2017 22:36:55 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:4321:4605:5007:7904:8957:9040:10004:10400:10848:11026:11232:11473:11657:11658:11914:12043:12438:12555:12690:12737:12740:12760:12895:13069:13311:13357:13439:14180:14181:14659:14721:21060:21080:21433:21451:30054:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: crowd57_57b4494582945 X-Filterd-Recvd-Size: 2940 Message-ID: <1491532601.3250.1.camel@perches.com> Subject: Re: [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro From: Joe Perches To: Matthias Kaehlcke Cc: Kalle Valo , ath9k Development , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Grant Grundler Date: Thu, 06 Apr 2017 19:36:41 -0700 In-Reply-To: <20170406235427.GC78690@google.com> References: <20170406212135.72157-1-mka@chromium.org> <1491514160.27353.102.camel@perches.com> <20170406235427.GC78690@google.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.3-0ubuntu0.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2017-04-06 at 16:54 -0700, Matthias Kaehlcke wrote: > Hi Joe, > > El Thu, Apr 06, 2017 at 02:29:20PM -0700 Joe Perches ha dit: > > > On Thu, 2017-04-06 at 14:21 -0700, Matthias Kaehlcke wrote: > > > The macro results are assigned to u8 variables/fields. Adding the cast > > > fixes plenty of clang warnings about "implicit conversion from 'int' to > > > 'u8'". > > > > > > Signed-off-by: Matthias Kaehlcke > > > --- > > > drivers/net/wireless/ath/ath9k/eeprom.h | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h > > > index 30bf722e33ed..31390af6c33e 100644 > > > --- a/drivers/net/wireless/ath/ath9k/eeprom.h > > > +++ b/drivers/net/wireless/ath/ath9k/eeprom.h > > > @@ -106,7 +106,7 @@ > > > #define AR9285_RDEXT_DEFAULT 0x1F > > > > > > #define ATH9K_POW_SM(_r, _s) (((_r) & 0x3f) << (_s)) > > > -#define FREQ2FBIN(x, y) ((y) ? ((x) - 2300) : (((x) - 4800) / 5)) > > > +#define FREQ2FBIN(x, y) (u8)((y) ? ((x) - 2300) : (((x) - 4800) / 5)) > > > > Maybe better to use: > > > > static inline u8 FREQ2FBIN(int x, int y) > > { > > if (y) > > return x - 2300; > > return (x - 4800) / 5; > > } > > Thanks for your suggestion! Unfortunately in this case an inline > function is not suitable since FREQ2FBIN() is mostly used for > structure initialization: > > static const struct ar9300_eeprom ar9300_default = { > ... > .calFreqPier2G = { > FREQ2FBIN(2412, 1), > FREQ2FBIN(2437, 1), > FREQ2FBIN(2472, 1) > }, > ... Maybe it's better to remove the second argument and write something like: #define FREQ2FBIN(x) \ (u8)(((x) >= 2300 && (x) <= 2555) ? (x) - 2300 : \ ((x) >= 4800 && (x) <= 4800 + (256 * 5) ? ((x) - 4800) / 5) : \ __builtin_const_p(x) ? BUILD_BUG_ON(1) : 0)