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

power: supply: bq2515x: 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 bq2515x->model_name to be NUL-terminated based on its usage with
sysfs_emit and format strings:

val->strval is assigned to bq2515x->model_name in
bq2515x_mains_get_property():
| val->strval = bq2515x->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 bq2515x_mains_get_property():
| static const struct power_supply_desc bq2515x_mains_desc = {
...
| .get_property = bq2515x_mains_get_property,

Moreover, no NUL-padding is required as bq2515x is zero-allocated in
bq2515x_charger.c:
| bq2515x = devm_kzalloc(dev, sizeof(*bq2515x), 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
Signed-off-by: Justin Stitt <justinstitt@google.com>
Similar-to: https://lore.kernel.org/all/20231020-strncpy-drivers-power-supply-bq24190_charger-c-v1-1-e896223cb795@google.com/
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20231020-strncpy-drivers-power-supply-bq2515x_charger-c-v1-1-46664c6edf78@google.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# ab907d99 02-Sep-2023 Biju Das <biju.das.jz@bp.renesas.com>

power: supply: bq2515x: Cleanup OF/ID table terminators

Some cleanups:
* Remove trailing comma in the terminator entry for OF/ID table.
* Drop a space from terminator entry for OF table.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230902200518.91585-3-biju.das.jz@bp.renesas.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# ef2730fb 02-Sep-2023 Biju Das <biju.das.jz@bp.renesas.com>

power: supply: bq2515x: Simpilfy bq2515x_read_properties() and probe()

Add struct bq2515x_info and replace device_id->info in struct
bq2515x_device.

Simpilfy bq2515x_read_properties() and probe() by adding struct
bq2425x_chip_info as match data for OF/ID tables and use
i2c_get_match_data for retrieving match data instead of ID lookup.

Drop enum bq2515x_id as there is no user.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230902200518.91585-2-biju.das.jz@bp.renesas.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>


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

power: supply: bq2515x: 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>


# 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>


# 66ac8df5 11-Sep-2020 Krzysztof Kozlowski <krzk@kernel.org>

power: supply: bq2515x: fix kerneldoc

Fix kerneldoc W=1 warning:

drivers/power/supply/bq2515x_charger.c:189: warning:
Function parameter or member 'init_data' not described in 'bq2515x_device'

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 93d660de 24-Aug-2020 Rikard Falkeborn <rikard.falkeborn@gmail.com>

power: supply: bq2515x: Constify static variables

Constify a number of static variables that are not modified to allow the
compiler to put them in read-only memory.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 81bd45fc 13-Jul-2020 Alexander A. Klimov <grandmaster@al2klimov.de>

power: supply: bq2xxxx: Replace HTTP links with HTTPS ones

Rationale:
Reduces attack surface on kernel devs opening the links for MITM
as HTTPS traffic is much harder to manipulate.

Deterministic algorithm:
For each file:
If not .svg:
For each line:
If doesn't contain `\bxmlns\b`:
For each link, `\bhttp://[^# \t\r\n]*(?:\w|/)`:
If neither `\bgnu\.org/license`, nor `\bmozilla\.org/MPL\b`:
If both the HTTP and HTTPS versions
return 200 OK and serve the same content:
Replace HTTP with HTTPS.

Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
[also update recently added ti.com http links]
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>


# 44908459 20-Jul-2020 Ricardo Rivera-Matos <r-rivera-matos@ti.com>

power: supply: bq25150 introduce the bq25150

Introduce the bq2515x family of chargers.

The BQ2515X family of devices are highly integrated battery management
ICs that integrate the most common functions for wearable devices
namely a charger, an output voltage rail, ADC for battery and system
monitoring, and a push-button controller.

Datasheets:
bq25150 - http://www.ti.com/lit/ds/symlink/bq25150.pdf
bq25155 - http://www.ti.com/lit/ds/symlink/bq25155.pdf

Signed-off-by: Ricardo Rivera-Matos <r-rivera-matos@ti.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>