Move the code of brightness setting function guarded by mutex into separate function. This will be useful when used from trigger offload method. Signed-off-by: Marek Behún <kabel@xxxxxxxxxx> --- drivers/leds/leds-turris-omnia.c | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index c5a40afe5d45..2b51c14b8363 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -41,32 +41,43 @@ struct omnia_leds { struct omnia_led leds[]; }; -static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, - enum led_brightness brightness) +static int omnia_led_brightness_set(struct i2c_client *client, + struct omnia_led *led, + enum led_brightness brightness) { - struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev); - struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); - struct omnia_led *led = to_omnia_led(mc_cdev); u8 buf[5], state; int ret; - mutex_lock(&leds->lock); - led_mc_calc_color_components(&led->mc_cdev, brightness); buf[0] = CMD_LED_COLOR; buf[1] = led->reg; - buf[2] = mc_cdev->subled_info[0].brightness; - buf[3] = mc_cdev->subled_info[1].brightness; - buf[4] = mc_cdev->subled_info[2].brightness; + buf[2] = led->mc_cdev.subled_info[0].brightness; + buf[3] = led->mc_cdev.subled_info[1].brightness; + buf[4] = led->mc_cdev.subled_info[2].brightness; state = CMD_LED_STATE_LED(led->reg); if (buf[2] || buf[3] || buf[4]) state |= CMD_LED_STATE_ON; - ret = i2c_smbus_write_byte_data(leds->client, CMD_LED_STATE, state); + ret = i2c_smbus_write_byte_data(client, CMD_LED_STATE, state); if (ret >= 0 && (state & CMD_LED_STATE_ON)) - ret = i2c_master_send(leds->client, buf, 5); + ret = i2c_master_send(client, buf, 5); + + return ret < 0 ? ret : 0; +} + +static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev); + struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); + struct omnia_led *led = to_omnia_led(mc_cdev); + int ret; + + mutex_lock(&leds->lock); + + ret = omnia_led_brightness_set(leds->client, led, brightness); mutex_unlock(&leds->lock); -- 2.26.3