summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorMarek BehĂșn <marek.behun@nic.cz>2020-09-20 03:24:58 +0300
committerPavel Machek <pavel@ucw.cz>2020-09-30 19:53:28 +0300
commitb5a3b44f2ddc4af49420f430b208ff8060ab7555 (patch)
tree5424a2f076a5a645a235b4ff925bf17fbce724a7 /drivers/leds
parent5db8509349cea5df0e6562537d84f3e90fda3270 (diff)
downloadlinux-b5a3b44f2ddc4af49420f430b208ff8060ab7555.tar.xz
leds: pca963x: use flexible array
Instead of doing two allocations, allocate only once, by utilizing flexible array members. Signed-off-by: Marek BehĂșn <marek.behun@nic.cz> Cc: Peter Meerwald <p.meerwald@bct-electronic.com> Cc: Ricardo Ribalda <ribalda@kernel.org> Cc: Zahari Petkov <zahari@balena.io> Signed-off-by: Pavel Machek <pavel@ucw.cz>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-pca963x.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index a4096694925f..73dc00787bee 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -96,15 +96,7 @@ static const struct i2c_device_id pca963x_id[] = {
};
MODULE_DEVICE_TABLE(i2c, pca963x_id);
-struct pca963x_led;
-
-struct pca963x {
- struct pca963x_chipdef *chipdef;
- struct mutex mutex;
- struct i2c_client *client;
- struct pca963x_led *leds;
- unsigned long leds_on;
-};
+struct pca963x;
struct pca963x_led {
struct pca963x *chip;
@@ -115,6 +107,14 @@ struct pca963x_led {
u8 gfrq;
};
+struct pca963x {
+ struct pca963x_chipdef *chipdef;
+ struct mutex mutex;
+ struct i2c_client *client;
+ unsigned long leds_on;
+ struct pca963x_led leds[];
+};
+
static int pca963x_brightness(struct pca963x_led *led,
enum led_brightness brightness)
{
@@ -367,7 +367,6 @@ static int pca963x_probe(struct i2c_client *client,
struct device *dev = &client->dev;
struct pca963x_chipdef *chipdef;
struct pca963x_platform_data *pdata;
- struct pca963x_led *leds;
struct pca963x *chip;
int i, err;
@@ -389,26 +388,23 @@ static int pca963x_probe(struct i2c_client *client,
return -EINVAL;
}
- chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+ chip = devm_kzalloc(dev, struct_size(chip, leds, chipdef->n_leds),
+ GFP_KERNEL);
if (!chip)
return -ENOMEM;
- leds = devm_kcalloc(dev, chipdef->n_leds, sizeof(*leds), GFP_KERNEL);
- if (!leds)
- return -ENOMEM;
i2c_set_clientdata(client, chip);
mutex_init(&chip->mutex);
chip->chipdef = chipdef;
chip->client = client;
- chip->leds = leds;
/* Turn off LEDs by default*/
for (i = 0; i < chipdef->n_leds / 4; i++)
i2c_smbus_write_byte_data(client, chipdef->ledout_base + i, 0x00);
for (i = 0; i < chipdef->n_leds; i++) {
- struct pca963x_led *led = &leds[i];
+ struct pca963x_led *led = &chip->leds[i];
led->led_num = i;
led->chip = chip;