Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753356AbdLMPco (ORCPT ); Wed, 13 Dec 2017 10:32:44 -0500 Received: from dd39320.kasserver.com ([85.13.155.146]:39268 "EHLO dd39320.kasserver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753297AbdLMPcj (ORCPT ); Wed, 13 Dec 2017 10:32:39 -0500 Subject: Re: [PATCH 6/8] staging: pi433: use defines for shifting register values To: Valentin Vidic , Greg Kroah-Hartman Cc: =?UTF-8?Q?Simon_Sandstr=c3=b6m?= , Marcin Ciupak , Marcus Wolf , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org References: <20171213142156.3201-1-Valentin.Vidic@CARNet.hr> <20171213142156.3201-6-Valentin.Vidic@CARNet.hr> From: Marcus Wolf Message-ID: <70c9a1fc-31eb-27c4-1283-35590f8b80f6@smarthome-wolf.de> Date: Wed, 13 Dec 2017 17:32:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171213142156.3201-6-Valentin.Vidic@CARNet.hr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3189 Lines: 85 Am 13.12.2017 um 16:21 schrieb Valentin Vidic: > Avoid shifting by magic numbers and use defines instead: > > SHIFT_DATAMODUL_MODULATION_TYPE > SHIFT_LNA_CURRENT_GAIN > > Signed-off-by: Valentin Vidic > --- > drivers/staging/pi433/rf69.c | 4 ++-- > drivers/staging/pi433/rf69_registers.h | 2 ++ > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c > index b1e243e5bcac..8c4841c9d796 100644 > --- a/drivers/staging/pi433/rf69.c > +++ b/drivers/staging/pi433/rf69.c > @@ -102,7 +102,7 @@ enum modulation rf69_get_modulation(struct spi_device *spi) > > currentValue = rf69_read_reg(spi, REG_DATAMODUL); > > - switch ((currentValue & MASK_DATAMODUL_MODULATION_TYPE) >> 3) { // TODO improvement: change 3 to define > + switch ((currentValue & MASK_DATAMODUL_MODULATION_TYPE) >> SHIFT_DATAMODUL_MODULATION_TYPE) { As mentioned by Dan, this change isn't needed any more, since we don't need the shift right here, since the DATAMODUL_MODULATION_TYPE_OOK and DATAMODUL_MODULATION_TYPE_FSK already contains the bits at the correct position. > case DATAMODUL_MODULATION_TYPE_OOK: return OOK; > case DATAMODUL_MODULATION_TYPE_FSK: return FSK; > default: return UNDEF; > @@ -340,7 +340,7 @@ enum lnaGain rf69_get_lna_gain(struct spi_device *spi) > > currentValue = rf69_read_reg(spi, REG_LNA); > > - switch ((currentValue & MASK_LNA_CURRENT_GAIN) >> 3) { // improvement: change 3 to define > + switch ((currentValue & MASK_LNA_CURRENT_GAIN) >> SHIFT_LNA_CURRENT_GAIN) { Regarding my previous mail: I was wrong! This way is right!! BUT: I would prefer to have a solution, like it was done for the modulation type: Do not shift anything here, but introduce new defines (LNA_GAIN_AUTO_xyz...), that are used for the casees, having the bits set at the right position, so theycan be used without shifting. Be aware: The old defines must remain untouched, since they are needed for an other function. Thx, Marcus > case LNA_GAIN_AUTO: return automatic; > case LNA_GAIN_MAX: return max; > case LNA_GAIN_MAX_MINUS_6: return maxMinus6; > diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h > index 981b57d7cc0b..da12642cf249 100644 > --- a/drivers/staging/pi433/rf69_registers.h > +++ b/drivers/staging/pi433/rf69_registers.h > @@ -124,6 +124,7 @@ > #define MASK_DATAMODUL_MODE 0x06 > #define MASK_DATAMODUL_MODULATION_TYPE 0x18 > #define MASK_DATAMODUL_MODULATION_SHAPE 0x03 > +#define SHIFT_DATAMODUL_MODULATION_TYPE 3 > > #define DATAMODUL_MODE_PACKET 0x00 /* default */ > #define DATAMODUL_MODE_CONTINUOUS 0x40 > @@ -235,6 +236,7 @@ > #define MASK_LNA_ZIN 0x80 > #define MASK_LNA_CURRENT_GAIN 0x38 > #define MASK_LNA_GAIN 0x07 > +#define SHIFT_LNA_CURRENT_GAIN 3 > > #define LNA_GAIN_AUTO 0x00 /* default */ > #define LNA_GAIN_MAX 0x01 > -- Smarthome-Wolf UG (haftungsbeschränkt) Helene-Lange-Weg 23 80637 München Amtsgericht München, HRB 223529 Umastzsteuer-ID: DE304719911 Geschäftsführer: Marcus Wolf