Simplify the sysfs logic of the linear property by switching to a macro and a ternary operator.
Signed-off-by: Svyatoslav Ryhel <[email protected]> --- drivers/video/backlight/lm3533_bl.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/video/backlight/lm3533_bl.c b/drivers/video/backlight/lm3533_bl.c index c70b8a3bb301..36e6f027613a 100644 --- a/drivers/video/backlight/lm3533_bl.c +++ b/drivers/video/backlight/lm3533_bl.c @@ -23,6 +23,7 @@ #define LM3533_BL_MAX_BRIGHTNESS 255 #define LM3533_REG_CTRLBANK_AB_BCONF 0x1a +#define CTRLBANK_AB_BCONF_MODE(n) BIT(2 * (n) + 1) struct lm3533_bl { @@ -136,8 +137,9 @@ static ssize_t show_linear(struct device *dev, struct device_attribute *attr, char *buf) { struct lm3533_bl *bl = dev_get_drvdata(dev); + int id = lm3533_bl_get_ctrlbank_id(bl); + u8 mask = CTRLBANK_AB_BCONF_MODE(id); u32 val; - u8 mask; int linear; int ret; @@ -145,8 +147,6 @@ static ssize_t show_linear(struct device *dev, if (ret) return ret; - mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1); - if (val & mask) linear = 1; else @@ -160,23 +160,16 @@ static ssize_t store_linear(struct device *dev, const char *buf, size_t len) { struct lm3533_bl *bl = dev_get_drvdata(dev); + int id = lm3533_bl_get_ctrlbank_id(bl); unsigned long linear; - u8 mask; - u8 val; int ret; if (kstrtoul(buf, 0, &linear)) return -EINVAL; - mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1); - - if (linear) - val = mask; - else - val = 0; - ret = regmap_update_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF, - mask, val); + CTRLBANK_AB_BCONF_MODE(id), + linear ? CTRLBANK_AB_BCONF_MODE(id) : 0); if (ret) return ret; -- 2.51.0
