History log of /linux-master/drivers/power/supply/bq25980_charger.c
Revision Date Author Comments
# afb0379b 20-Oct-2023 Justin Stitt <justinstitt@google.com>

power: supply: bq25980: replace deprecated strncpy with strscpy

strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.

We expect bq->model_name to be NUL-terminated based on its usage with
sysfs_emit and format strings:

val->strval is assigned to bq->model_name in
bq25980_get_charger_property():
| val->strval = bq->model_name;

... then in power_supply_sysfs.c we use value.strval with a format string:
| ret = sysfs_emit(buf, "%s\n", value.strval);

we assigned value.strval via:
| ret = power_supply_get_property(psy, psp, &value);
... which invokes psy->desc->get_property():
| return psy->desc->get_property(psy, psp, val);

with bq25980_get_charger_property():
| static const struct power_supply_desc bq25980_power_supply_desc = {
...
| .get_property = bq25980_get_charger_property,

Moreover, no NUL-padding is required as bq is zero-allocated in
bq25980_charger.c:
| bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL);

Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer
without unnecessarily NUL-padding.

Let's also opt to use the more idiomatic strscpy() usage of (dest, src,
sizeof(dest)) as this more closely ties the destination buffer and the
length.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Similar-to: https://lore.kernel.org/all/20231020-strncpy-drivers-power-supply-bq24190_charger-c-v1-1-e896223cb795@google.com/
Similar-to: https://lore.kernel.org/all/20231020-strncpy-drivers-power-supply-bq2515x_charger-c-v1-1-46664c6edf78@google.com/
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20231020-strncpy-drivers-power-supply-bq25980_charger-c-v1-1-7b93be54537b@google.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# fe20b1dc 17-May-2023 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

power: supply: Switch i2c drivers back to use .probe()

After commit b8a1a4cd5a98 ("i2c: Provide a temporary .probe_new()
call-back type"), all drivers being converted to .probe_new() and then
03c835f498b5 ("i2c: Switch .probe() to not take an id parameter") convert
back to (the new) .probe() to be able to eventually drop .probe_new() from
struct i2c_driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 79fc7c26 18-Nov-2022 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

power: supply: bq25980: Convert to i2c's .probe_new()

.probe_new() doesn't get the i2c_device_id * parameter, so determine
that explicitly in the probe function.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# be5f08f0 14-Feb-2022 Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>

power: supply: bq25980: Implements POWER_SUPPLY_CHARGE_TYPE_BYPASS

This patch remaps the bypass operation from POWER_SUPPLY_CHARGE_TYPE_FAST
to POWER_SUPPLY_CHARGE_TYPE_BYPASS.

Signed-off-by: Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 25fd3303 14-Dec-2021 Linus Walleij <linus.walleij@linaro.org>

power: supply_core: Pass pointer to battery info

The function to retrieve battery info (from the device tree) assumes
we have a static info struct that gets populated by calling into
power_supply_get_battery_info().

This is awkward since I want to support tables of static battery
info by just assigning a pointer to all info based on e.g. a
compatible value in the device tree.

We also have a mixture of static and dynamically allocated
variables here.

Bite the bullet and let power_supply_get_battery_info() allocate
also the memory used for the very top level
struct power_supply_battery_info container. Pass pointers
around and lifecycle this with the psy device just like the
stuff we allocate inside it.

Change all current users over.

As part of the change, initializers need to be added to some
previously uninitialized fields in struct
power_supply_battery_info.

Reviewed-By: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 04722cec 10-Feb-2021 Ricardo Rivera-Matos <r-rivera-matos@ti.com>

power: supply: bq25980: Move props from battery node

Currently POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE are exposed on
the battery node and this is incorrect.

This patch exposes both of them on the charger node rather
than the battery node.

Fixes: 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
Signed-off-by: Ricardo Rivera-Matos <r-rivera-matos@ti.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 79bcb02b 21-Jan-2021 xinjian <xinjian@yulong.com>

power: supply: bq25980: Fix repetive bq25975 with bq25960

The i2c_device_id bq25975 is repeated, and should be bq25960.

Signed-off-by: xinjian <xinjian@yulong.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 6c59a17b 09-Oct-2020 Dan Murphy <dmurphy@ti.com>

power: supply: bq25980: Fix uninitialized wd_reg_val and overrun

Fix the issue when 'i' is equal to array size then array index over
runs the array when checking for the watch dog value.

Fixes: 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# d4fbca83 05-Oct-2020 Dan Murphy <dmurphy@ti.com>

power: supply: bq25980: Fix uninitialized wd_reg_val

Fix the uninitialized wd_reg_val if the for..loop was not successful in
finding an appropriate match.

Fixes: 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 4b464bad 06-Oct-2020 Colin Ian King <colin.king@canonical.com>

power: supply: bq25980: remove redundant zero check on ret

Currently ret is assigned to zero and the following statement checks
if it is non-zero. This check is redundant and can be removed

Addresses-Coverity: ("Logically dead code")
Fixes: 5069185fc18e ("power: supply: bq25980: Add support for the BQ259xx family")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 5069185f 31-Aug-2020 Dan Murphy <dmurphy@ti.com>

power: supply: bq25980: Add support for the BQ259xx family

Add support for the BQ25980, BQ25975 and BQ25960 family of flash
chargers.

Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>