Skip to content

Commit

Permalink
Merge tag 'led-fixes-for-5.1-rc3' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/kernel/git/j.anaszewski/linux-leds

Pull LED fixes from Jacek Anaszewski:

 - fix refcnt leak on interface rename

 - use memcpy in device_name_store() to avoid including garbage from a
   previous, longer value in the device_name

 - fix a potential NULL pointer dereference in case of_match_device()
   cannot find a match

* tag 'led-fixes-for-5.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds:
  leds: trigger: netdev: use memcpy in device_name_store
  leds: pca9532: fix a potential NULL pointer dereference
  leds: trigger: netdev: fix refcnt leak on interface rename
  • Loading branch information
torvalds committed Mar 30, 2019
2 parents 3af9a52 + 9093464 commit b5c8314
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 6 additions & 2 deletions drivers/leds/leds-pca9532.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ static int pca9532_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int devid;
const struct of_device_id *of_id;
struct pca9532_data *data = i2c_get_clientdata(client);
struct pca9532_platform_data *pca9532_pdata =
dev_get_platdata(&client->dev);
Expand All @@ -528,8 +529,11 @@ static int pca9532_probe(struct i2c_client *client,
dev_err(&client->dev, "no platform data\n");
return -EINVAL;
}
devid = (int)(uintptr_t)of_match_device(
of_pca9532_leds_match, &client->dev)->data;
of_id = of_match_device(of_pca9532_leds_match,
&client->dev);
if (unlikely(!of_id))
return -EINVAL;
devid = (int)(uintptr_t) of_id->data;
} else {
devid = id->driver_data;
}
Expand Down
16 changes: 7 additions & 9 deletions drivers/leds/trigger/ledtrig-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ static ssize_t device_name_store(struct device *dev,
trigger_data->net_dev = NULL;
}

strncpy(trigger_data->device_name, buf, size);
memcpy(trigger_data->device_name, buf, size);
trigger_data->device_name[size] = 0;
if (size > 0 && trigger_data->device_name[size - 1] == '\n')
trigger_data->device_name[size - 1] = 0;

Expand Down Expand Up @@ -301,11 +302,11 @@ static int netdev_trig_notify(struct notifier_block *nb,
container_of(nb, struct led_netdev_data, notifier);

if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE
&& evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER
&& evt != NETDEV_CHANGENAME)
&& evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER)
return NOTIFY_DONE;

if (strcmp(dev->name, trigger_data->device_name))
if (!(dev == trigger_data->net_dev ||
(evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name))))
return NOTIFY_DONE;

cancel_delayed_work_sync(&trigger_data->work);
Expand All @@ -320,12 +321,9 @@ static int netdev_trig_notify(struct notifier_block *nb,
dev_hold(dev);
trigger_data->net_dev = dev;
break;
case NETDEV_CHANGENAME:
case NETDEV_UNREGISTER:
if (trigger_data->net_dev) {
dev_put(trigger_data->net_dev);
trigger_data->net_dev = NULL;
}
dev_put(trigger_data->net_dev);
trigger_data->net_dev = NULL;
break;
case NETDEV_UP:
case NETDEV_CHANGE:
Expand Down

0 comments on commit b5c8314

Please sign in to comment.