Skip to content

Commit

Permalink
leds: as3645a: Use generic support for composing LED names
Browse files Browse the repository at this point in the history
Switch to using generic LED support for composing LED class
device name.

After switching to new led_classdev_register_ext() the validity
of struct led_classdev's name property is no longer guaranteed,
and therefore rely on struct device's kobj.name instead.

Signed-off-by: Jacek Anaszewski <[email protected]>
Cc: Sakari Ailus <[email protected]>
Acked-by: Pavel Machek <[email protected]>
  • Loading branch information
jacek-anaszewski committed Jul 25, 2019
1 parent 5b95cb0 commit b1f2449
Showing 1 changed file with 28 additions and 46 deletions.
74 changes: 28 additions & 46 deletions drivers/leds/leds-as3645a.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ struct as3645a_config {
u32 peak;
};

struct as3645a_names {
char flash[32];
char indicator[32];
};

struct as3645a {
struct i2c_client *client;

Expand Down Expand Up @@ -484,12 +479,10 @@ static int as3645a_detect(struct as3645a *flash)
}

static int as3645a_parse_node(struct as3645a *flash,
struct as3645a_names *names,
struct fwnode_handle *fwnode)
{
struct as3645a_config *cfg = &flash->cfg;
struct fwnode_handle *child;
const char *name;
int rval;

fwnode_for_each_child_node(fwnode, child) {
Expand Down Expand Up @@ -517,17 +510,6 @@ static int as3645a_parse_node(struct as3645a *flash,
return -ENODEV;
}

rval = fwnode_property_read_string(flash->flash_node, "label", &name);
if (!rval) {
strlcpy(names->flash, name, sizeof(names->flash));
} else if (is_of_node(fwnode)) {
snprintf(names->flash, sizeof(names->flash),
"%pOFn:flash", to_of_node(fwnode));
} else {
dev_err(&flash->client->dev, "flash node has no label!\n");
return -EINVAL;
}

rval = fwnode_property_read_u32(flash->flash_node, "flash-timeout-us",
&cfg->flash_timeout_us);
if (rval < 0) {
Expand Down Expand Up @@ -565,17 +547,6 @@ static int as3645a_parse_node(struct as3645a *flash,
goto out_err;
}

rval = fwnode_property_read_string(flash->indicator_node, "label",
&name);
if (!rval) {
strlcpy(names->indicator, name, sizeof(names->indicator));
} else if (is_of_node(fwnode)) {
snprintf(names->indicator, sizeof(names->indicator),
"%pOFn:indicator", to_of_node(fwnode));
} else {
dev_err(&flash->client->dev, "indicator node has no label!\n");
return -EINVAL;
}

rval = fwnode_property_read_u32(flash->indicator_node,
"led-max-microamp",
Expand All @@ -595,21 +566,25 @@ static int as3645a_parse_node(struct as3645a *flash,
return rval;
}

static int as3645a_led_class_setup(struct as3645a *flash,
struct as3645a_names *names)
static int as3645a_led_class_setup(struct as3645a *flash)
{
struct led_classdev *fled_cdev = &flash->fled.led_cdev;
struct led_classdev *iled_cdev = &flash->iled_cdev;
struct led_init_data init_data = {};
struct led_flash_setting *cfg;
int rval;

iled_cdev->name = names->indicator;
iled_cdev->brightness_set_blocking = as3645a_set_indicator_brightness;
iled_cdev->max_brightness =
flash->cfg.indicator_max_ua / AS_INDICATOR_INTENSITY_STEP;
iled_cdev->flags = LED_CORE_SUSPENDRESUME;

rval = led_classdev_register(&flash->client->dev, iled_cdev);
init_data.fwnode = flash->indicator_node;
init_data.devicename = AS_NAME;
init_data.default_label = "indicator";

rval = led_classdev_register_ext(&flash->client->dev, iled_cdev,
&init_data);
if (rval < 0)
return rval;

Expand All @@ -627,23 +602,30 @@ static int as3645a_led_class_setup(struct as3645a *flash,

flash->fled.ops = &as3645a_led_flash_ops;

fled_cdev->name = names->flash;
fled_cdev->brightness_set_blocking = as3645a_set_assist_brightness;
/* Value 0 is off in LED class. */
fled_cdev->max_brightness =
as3645a_current_to_reg(flash, false,
flash->cfg.assist_max_ua) + 1;
fled_cdev->flags = LED_DEV_CAP_FLASH | LED_CORE_SUSPENDRESUME;

rval = led_classdev_flash_register(&flash->client->dev, &flash->fled);
if (rval) {
led_classdev_unregister(iled_cdev);
dev_err(&flash->client->dev,
"led_classdev_flash_register() failed, error %d\n",
rval);
}
init_data.fwnode = flash->flash_node;
init_data.devicename = AS_NAME;
init_data.default_label = "flash";

rval = led_classdev_flash_register_ext(&flash->client->dev,
&flash->fled, &init_data);
if (rval)
goto out_err;

return rval;

out_err:
led_classdev_unregister(iled_cdev);
dev_err(&flash->client->dev,
"led_classdev_flash_register() failed, error %d\n",
rval);
return rval;
}

static int as3645a_v4l2_setup(struct as3645a *flash)
Expand All @@ -667,8 +649,9 @@ static int as3645a_v4l2_setup(struct as3645a *flash)
},
};

strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name));
strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfgind.dev_name));
strlcpy(cfg.dev_name, led->dev->kobj.name, sizeof(cfg.dev_name));
strlcpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name,
sizeof(cfgind.dev_name));

flash->vf = v4l2_flash_init(
&flash->client->dev, flash->flash_node, &flash->fled, NULL,
Expand All @@ -689,7 +672,6 @@ static int as3645a_v4l2_setup(struct as3645a *flash)

static int as3645a_probe(struct i2c_client *client)
{
struct as3645a_names names;
struct as3645a *flash;
int rval;

Expand All @@ -702,7 +684,7 @@ static int as3645a_probe(struct i2c_client *client)

flash->client = client;

rval = as3645a_parse_node(flash, &names, dev_fwnode(&client->dev));
rval = as3645a_parse_node(flash, dev_fwnode(&client->dev));
if (rval < 0)
return rval;

Expand All @@ -717,7 +699,7 @@ static int as3645a_probe(struct i2c_client *client)
if (rval)
goto out_mutex_destroy;

rval = as3645a_led_class_setup(flash, &names);
rval = as3645a_led_class_setup(flash);
if (rval)
goto out_mutex_destroy;

Expand Down

0 comments on commit b1f2449

Please sign in to comment.