From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Date: Fri, 15 May 2015 17:10:26 +0000 Subject: Re: [patch] regulator: max77686: fix a shift wrapping bug Message-Id: <1431709826.15709.15.camel@perches.com> List-Id: References: <20150515092501.GB21508@mwanda> <5555C814.7030405@samsung.com> In-Reply-To: <5555C814.7030405@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Chanwoo Choi Cc: Dan Carpenter , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org On Fri, 2015-05-15 at 19:19 +0900, Chanwoo Choi wrote: > On 05/15/2015 06:25 PM, Dan Carpenter wrote: > > We need to be able to handle more than 32 bits here because "id" can go > > up to MAX77686_BUCK9 (34). ->gpio_enabled is a u64 so that's fine > > already. > > > > Fixes: 3307e9025d29 ('regulator: max77686: Add GPIO control') > > Signed-off-by: Dan Carpenter Alternate suggested patch below: > > diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c [] > > @@ -121,7 +121,7 @@ static unsigned int max77686_map_normal_mode(struct max77686_data *max77686, > > - if (max77686->gpio_enabled & (1 << id)) > > + if (max77686->gpio_enabled & (1ULL << id)) [] > > @@ -277,7 +277,7 @@ static int max77686_of_parse_cb(struct device_node *np, > > if (gpio_is_valid(config->ena_gpio)) { > > - max77686->gpio_enabled |= (1 << desc->id); > > + max77686->gpio_enabled |= (1ULL << desc->id); [] > Looks good to me. > Reviewed-by: Chanwoo Choi This could be better with DECLARE_BITMAP and test_bit/set_bit --- drivers/regulator/max77686.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c index 23b7c06..17ccf36 100644 --- a/drivers/regulator/max77686.c +++ b/drivers/regulator/max77686.c @@ -88,7 +88,7 @@ enum max77686_ramp_rate { }; struct max77686_data { - u64 gpio_enabled:MAX77686_REGULATORS; + DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS); /* Array indexed by regulator id */ unsigned int opmode[MAX77686_REGULATORS]; @@ -121,7 +121,7 @@ static unsigned int max77686_map_normal_mode(struct max77686_data *max77686, case MAX77686_BUCK8: case MAX77686_BUCK9: case MAX77686_LDO20 ... MAX77686_LDO22: - if (max77686->gpio_enabled & (1 << id)) + if (test_bit(id, max77686->gpio_enabled)) return MAX77686_GPIO_CONTROL; } @@ -277,7 +277,7 @@ static int max77686_of_parse_cb(struct device_node *np, } if (gpio_is_valid(config->ena_gpio)) { - max77686->gpio_enabled |= (1 << desc->id); + set_bit(desc->id, max77686->gpio_enabled); return regmap_update_bits(config->regmap, desc->enable_reg, desc->enable_mask, From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934812AbbEORKb (ORCPT ); Fri, 15 May 2015 13:10:31 -0400 Received: from smtprelay0073.hostedemail.com ([216.40.44.73]:51757 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933313AbbEORK3 (ORCPT ); Fri, 15 May 2015 13:10:29 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:421:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3622:3867:3868:3871:3874:4250:4321:5007:6261:7903:10004:10400:10848:11026:11232:11473:11658:11914:12043:12295:12296:12438:12517:12519:12555:12740:13019:21080:21088,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: foot09_78613cb8fc75f X-Filterd-Recvd-Size: 3242 Message-ID: <1431709826.15709.15.camel@perches.com> Subject: Re: [patch] regulator: max77686: fix a shift wrapping bug From: Joe Perches To: Chanwoo Choi Cc: Dan Carpenter , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Date: Fri, 15 May 2015 10:10:26 -0700 In-Reply-To: <5555C814.7030405@samsung.com> References: <20150515092501.GB21508@mwanda> <5555C814.7030405@samsung.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.11-0ubuntu3 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 Fri, 2015-05-15 at 19:19 +0900, Chanwoo Choi wrote: > On 05/15/2015 06:25 PM, Dan Carpenter wrote: > > We need to be able to handle more than 32 bits here because "id" can go > > up to MAX77686_BUCK9 (34). ->gpio_enabled is a u64 so that's fine > > already. > > > > Fixes: 3307e9025d29 ('regulator: max77686: Add GPIO control') > > Signed-off-by: Dan Carpenter Alternate suggested patch below: > > diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c [] > > @@ -121,7 +121,7 @@ static unsigned int max77686_map_normal_mode(struct max77686_data *max77686, > > - if (max77686->gpio_enabled & (1 << id)) > > + if (max77686->gpio_enabled & (1ULL << id)) [] > > @@ -277,7 +277,7 @@ static int max77686_of_parse_cb(struct device_node *np, > > if (gpio_is_valid(config->ena_gpio)) { > > - max77686->gpio_enabled |= (1 << desc->id); > > + max77686->gpio_enabled |= (1ULL << desc->id); [] > Looks good to me. > Reviewed-by: Chanwoo Choi This could be better with DECLARE_BITMAP and test_bit/set_bit --- drivers/regulator/max77686.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c index 23b7c06..17ccf36 100644 --- a/drivers/regulator/max77686.c +++ b/drivers/regulator/max77686.c @@ -88,7 +88,7 @@ enum max77686_ramp_rate { }; struct max77686_data { - u64 gpio_enabled:MAX77686_REGULATORS; + DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS); /* Array indexed by regulator id */ unsigned int opmode[MAX77686_REGULATORS]; @@ -121,7 +121,7 @@ static unsigned int max77686_map_normal_mode(struct max77686_data *max77686, case MAX77686_BUCK8: case MAX77686_BUCK9: case MAX77686_LDO20 ... MAX77686_LDO22: - if (max77686->gpio_enabled & (1 << id)) + if (test_bit(id, max77686->gpio_enabled)) return MAX77686_GPIO_CONTROL; } @@ -277,7 +277,7 @@ static int max77686_of_parse_cb(struct device_node *np, } if (gpio_is_valid(config->ena_gpio)) { - max77686->gpio_enabled |= (1 << desc->id); + set_bit(desc->id, max77686->gpio_enabled); return regmap_update_bits(config->regmap, desc->enable_reg, desc->enable_mask,