summaryrefslogtreecommitdiffstats
path: root/drivers/power/supply/surface_battery.c
Commit message (Collapse)AuthorAgeFilesLines
* power: supply: surface_battery: replace deprecated strncpy with strscpyJustin Stitt2023-10-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 bat->name to be NUL-terminated based on its usage with strcmp(): power_supply_core.c: 445: return strcmp(psy->desc->name, name) == 0; ... and also by the manual `... - 1` for the length argument of the original strncpy() invocation. Furthermore, no NUL-padding is needed as bat is zero-allocated before calling spwr_battery_init(): 826: bat = devm_kzalloc(&sdev->dev, sizeof(*bat), GFP_KERNEL); 827: if (!bat) 828: return -ENOMEM; 829: 830: spwr_battery_init(bat, sdev, p->registry, p->name); ... this means any further NUL-byte assignments (like the ones that strncpy() does) are redundant. 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)). 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> Link: https://lore.kernel.org/r/20231020-strncpy-drivers-power-supply-surface_battery-c-v2-1-29ed16b2caf1@google.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
* platform/surface: aggregator: Enforce use of target-ID enum in device ID macrosMaximilian Luz2023-02-021-2/+2
| | | | | | | | | | | | | | | | | | Similar to the target category (TC), the target ID (TID) can be one value out of a small number of choices, given in enum ssam_ssh_tid. In the device ID macros, SSAM_SDEV() and SSAM_VDEV() we already use text expansion to, both, remove some textual clutter for the target category values and enforce that the value belongs to the known set. Now that we know the names for the target IDs, use the same trick for them as well. Also rename the SSAM_ANY_x macros to SSAM_SSH_x_ANY to better fit in. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20221202223327.690880-9-luzmaximilian@gmail.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* power/supply: surface_battery: Use client device wrappers for notifier ↵Maximilian Luz2022-06-131-2/+2
| | | | | | | | | | | | | registration Use newly introduced client device wrapper functions for notifier registration and unregistration. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20220527023447.2460025-7-luzmaximilian@gmail.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* power: supply: surface_battery: Fix battery event handlingMaximilian Luz2021-05-131-2/+12
| | | | | | | | | | | | | | | | The battery subsystem of the Surface Aggregator Module EC requires us to register the battery notifier with instance ID 0. However, battery events are actually sent with the instance ID corresponding to the device, which is nonzero. Thus, the strict-matching approach doesn't work here and will discard events that the driver is expected to handle. To fix this we have to fall back on notifier matching by target-category only and have to manually check the instance ID in the notifier callback. Fixes: 167f77f7d0b3 ("power: supply: Add battery driver for Surface Aggregator Module") Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
* power: supply: surface-battery: Make some symbols staticQiheng Lin2021-04-121-2/+2
| | | | | | | | | | | | | | | | | The sparse tool complains as follows: drivers/power/supply/surface_battery.c:700:1: warning: symbol 'dev_attr_alarm' was not declared. Should it be static? drivers/power/supply/surface_battery.c:805:1: warning: symbol 'surface_battery_pm_ops' was not declared. Should it be static? This symbol is not used outside of surface_battery.c, so this commit marks it static. Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Qiheng Lin <linqiheng@huawei.com> Acked-by: Maximilian Luz <luzmaximilian@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
* power: supply: Add battery driver for Surface Aggregator ModuleMaximilian Luz2021-04-081-0/+865
On newer Microsoft Surface models (specifically 7th-generation, i.e. Surface Pro 7, Surface Book 3, Surface Laptop 3, and Surface Laptop Go), battery and AC status/information is no longer handled via standard ACPI devices, but instead directly via the Surface System Aggregator Module (SSAM), i.e. the embedded controller on those devices. While on previous generation models, battery status is also handled via SSAM, an ACPI shim was present to translate the standard ACPI battery interface to SSAM requests. The SSAM interface itself, which is modeled closely after the ACPI interface, has not changed. This commit introduces a new SSAM client device driver to support battery status/information via the aforementioned interface on said Surface models. It is in parts based on the standard ACPI battery driver. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>