FAILED: patch "[PATCH] power: supply: qcom_smbx: validate battery float voltage" failed to apply to 6.12-stable tree
Sasha Levin
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x a2d7dc538da2cb4a7426f0742197e762cb635f38
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From a2d7dc538da2cb4a7426f0742197e762cb635f38 Mon Sep 17 00:00:00 2001
From: Robin Snyders <[email protected]>
Date: Wed, 12 Aug 2026 01:30:01 +0200
Subject: [PATCH] power: supply: qcom_smbx: validate battery float voltage
power_supply_get_battery_info() leaves absent optional properties at -EINVAL. The driver uses voltage_max_design_uv without checking it, so a missing or out-of-range value can become an invalid float-voltage selector.
Prefer the constant-charge voltage because it describes the charger's CV target, then fall back to the battery design voltage. Both properties are optional in the simple-battery binding, so preserve the hardware setting when neither is present. Reject a supplied target outside the SMB2 range.
smb_init_hw() enables charging before battery data is parsed and before the remaining fallible probe steps. Save the initial charging-enable bit and install a managed rollback before initialization. Keep the rollback active across battery-info, voltage, IRQ and wake-IRQ setup, then remove it only after probe can no longer fail.
--- drivers/power/supply/qcom_smbx.c | 61 ++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-)
drivers/power/supply/qcom_smbx.c +58 -3
@@ -353,6 +353,7 @@/* pmi8998 registers represent current in increments of 1/40th of an amp */ #define CURRENT_SCALE_FACTOR 25000#define SMB2_FLOAT_VOLTAGE_MIN_UV 3487500 +#define SMB2_FLOAT_VOLTAGE_MAX_UV 4920000#define SMB2_FLOAT_VOLTAGE_STEP_UV 7500/* clang-format on */
@@ -380,6 +381,7 @@ struct smb_init_register {* @base: Base address for smb registers * @regmap: Register map * @batt_info: Battery data from DT +* @initial_charge_enable: Charging enable state before hardware setup * @status_change_work: Worker to handle plug/unplug events * @cable_irq: USB plugin IRQ * @wakeup_enabled: If the cable IRQ will cause a wakeup
@@ -393,6 +395,7 @@ struct smb_chip {unsigned int base;struct regmap *regmap;struct power_supply_battery_info *batt_info; +u8 initial_charge_enable;struct delayed_work status_change_work;int cable_irq;
@@ -905,6 +908,19 @@ static int smb_init_hw(struct smb_chip *chip)return 0 ; } +static void smb_restore_charge_enable (void *data) +{ +struct smb_chip *chip = data; +int rc; + + rc =regmap_update_bits (chip->regmap, + chip->base +CHARGING_ENABLE_CMD , +CHARGING_ENABLE_CMD_BIT , + chip->initial_charge_enable); +if (rc <0 ) +dev_err (chip->dev,"Couldn't restore charging state: %d\n" , rc); +} +static int smb_init_irq (struct smb_chip *chip,int *irq,const char *name,irqreturn_t (*handler)(int irq,void *data)) {
@@ -931,6 +947,9 @@ static int smb_probe(struct platform_device *pdev)struct power_supply_config supply_config = {};struct power_supply_desc *desc;struct smb_chip *chip; +unsigned int charge_enable; +unsigned int float_voltage_sel; +int float_voltage_uv;int rc, irq; chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL );
@@ -961,6 +980,18 @@ static int smb_probe(struct platform_device *pdev) "Couldn't get usbin_i IIO channel\n"); } + rc =regmap_read (chip->regmap, chip->base +CHARGING_ENABLE_CMD , + &charge_enable); +if (rc <0 ) +return dev_err_probe (chip->dev, rc, +"Couldn't read charging state\n" ); + + chip->initial_charge_enable = charge_enable &CHARGING_ENABLE_CMD_BIT ; + rc =devm_add_action_or_reset (chip->dev, smb_restore_charge_enable, chip); +if (rc) +return dev_err_probe (chip->dev, rc, +"Couldn't register charging state rollback\n" ); + rc =smb_init_hw (chip);if (rc <0 )return rc;
@@ -995,13 +1026,35 @@ static int smb_probe(struct platform_device *pdev)return dev_err_probe (chip->dev, rc,"Failed to init status change work\n" ); - rc = (chip->batt_info->voltage_max_design_uv - -SMB2_FLOAT_VOLTAGE_MIN_UV ) /SMB2_FLOAT_VOLTAGE_STEP_UV ; +if (power_supply_battery_info_has_prop (chip->batt_info, +POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX )) { + float_voltage_uv = + chip->batt_info->constant_charge_voltage_max_uv; + }else if (power_supply_battery_info_has_prop (chip->batt_info, +POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN )) { + float_voltage_uv = chip->batt_info->voltage_max_design_uv; + }else { +dev_warn (chip->dev,"No battery float voltage; preserving hardware setting\n" ); + goto skip_float_voltage; + } + +if (float_voltage_uv <SMB2_FLOAT_VOLTAGE_MIN_UV || + float_voltage_uv >SMB2_FLOAT_VOLTAGE_MAX_UV ) +return dev_err_probe (chip->dev, -EINVAL , +"float voltage %d uV outside %d-%d uV\n" , + float_voltage_uv, +SMB2_FLOAT_VOLTAGE_MIN_UV , +SMB2_FLOAT_VOLTAGE_MAX_UV ); + + float_voltage_sel = + (float_voltage_uv -SMB2_FLOAT_VOLTAGE_MIN_UV ) / +SMB2_FLOAT_VOLTAGE_STEP_UV ; rc =regmap_update_bits (chip->regmap, chip->base +FLOAT_VOLTAGE_CFG , -FLOAT_VOLTAGE_SETTING_MASK , rc); +FLOAT_VOLTAGE_SETTING_MASK , float_voltage_sel);if (rc <0 )return dev_err_probe (chip->dev, rc,"Couldn't set vbat max\n" ); +skip_float_voltage: rc =smb_init_irq (chip, &irq,"bat-ov" , smb_handle_batt_overvoltage);if (rc <0 )return rc;
@@ -1025,6 +1078,8 @@ static int smb_probe(struct platform_device *pdev)if (rc <0 )return dev_err_probe (chip->dev, rc,"Couldn't set wake irq\n" ); +devm_remove_action (chip->dev, smb_restore_charge_enable, chip); +platform_set_drvdata (pdev, chip);/* Initialise charger state */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 power: supply: pmi8998_charger: rename to qcom_smbx
From: Casey Connolly <[email protected]>
[ Upstream commit 5ec53bcc7fce6801977a0c125fb726d7b0e9102c ]
Prepare to add smb5 support by making variables and the file name more generic. Also take the opportunity to remove the "_charger" suffix since smb2 always refers to a charger.
Stable-dep-of: a2d7dc538da2 ("power: supply: qcom_smbx: validate battery float voltage")
---
drivers/power/supply/Makefile | 2 +-
.../{qcom_pmi8998_charger.c => qcom_smbx.c} | 148 +++++++++---------
2 files changed, 75 insertions(+), 75 deletions(-)
rename drivers/power/supply/{qcom_pmi8998_charger.c => qcom_smbx.c} (88%)drivers/power/supply/Makefile +1 -1
@@ -115,5 +115,5 @@ obj-$(CONFIG_BATTERY_ACER_A500) += acer_a500_battery.o obj-$(CONFIG_BATTERY_SURFACE) += surface_battery.o obj-$(CONFIG_CHARGER_SURFACE) += surface_charger.o obj-$(CONFIG_BATTERY_UG3105) += ug3105_battery.o -obj-$(CONFIG_CHARGER_QCOM_SMB2) += qcom_pmi8998_charger.o +obj-$(CONFIG_CHARGER_QCOM_SMB2) += qcom_smbx.o obj-$(CONFIG_FUEL_GAUGE_MM8013) += mm8013.o
drivers/power/supply/qcom_smbx.c renamed from drivers/power/supply/qcom_pmi8998_charger.c +74 -74
405 lines not on this page · raw message
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 power: supply: qcom_smbx: validate battery float voltage
From: Robin Snyders <[email protected]>
[ Upstream commit a2d7dc538da2cb4a7426f0742197e762cb635f38 ]
power_supply_get_battery_info() leaves absent optional properties at -EINVAL. The driver uses voltage_max_design_uv without checking it, so a missing or out-of-range value can become an invalid float-voltage selector.
Prefer the constant-charge voltage because it describes the charger's CV target, then fall back to the battery design voltage. Both properties are optional in the simple-battery binding, so preserve the hardware setting when neither is present. Reject a supplied target outside the SMB2 range.
smb_init_hw() enables charging before battery data is parsed and before the remaining fallible probe steps. Save the initial charging-enable bit and install a managed rollback before initialization. Keep the rollback active across battery-info, voltage, IRQ and wake-IRQ setup, then remove it only after probe can no longer fail.
--- drivers/power/supply/qcom_smbx.c | 61 ++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-)
drivers/power/supply/qcom_smbx.c +58 -3
@@ -350,6 +350,7 @@/* pmi8998 registers represent current in increments of 1/40th of an amp */ #define CURRENT_SCALE_FACTOR 25000#define SMB2_FLOAT_VOLTAGE_MIN_UV 3487500 +#define SMB2_FLOAT_VOLTAGE_MAX_UV 4920000#define SMB2_FLOAT_VOLTAGE_STEP_UV 7500/* clang-format on */
@@ -377,6 +378,7 @@ struct smb_init_register {* @base: Base address for smb registers * @regmap: Register map * @batt_info: Battery data from DT +* @initial_charge_enable: Charging enable state before hardware setup * @status_change_work: Worker to handle plug/unplug events * @cable_irq: USB plugin IRQ * @wakeup_enabled: If the cable IRQ will cause a wakeup
@@ -390,6 +392,7 @@ struct smb_chip {unsigned int base;struct regmap *regmap;struct power_supply_battery_info *batt_info; +u8 initial_charge_enable;struct delayed_work status_change_work;int cable_irq;
@@ -904,6 +907,19 @@ static int smb_init_hw(struct smb_chip *chip)return 0 ; } +static void smb_restore_charge_enable (void *data) +{ +struct smb_chip *chip = data; +int rc; + + rc =regmap_update_bits (chip->regmap, + chip->base +CHARGING_ENABLE_CMD , +CHARGING_ENABLE_CMD_BIT , + chip->initial_charge_enable); +if (rc <0 ) +dev_err (chip->dev,"Couldn't restore charging state: %d\n" , rc); +} +static int smb_init_irq (struct smb_chip *chip,int *irq,const char *name,irqreturn_t (*handler)(int irq,void *data)) {
@@ -931,6 +947,9 @@ static int smb_probe(struct platform_device *pdev)struct power_supply_config supply_config = {};struct power_supply_desc *desc;struct smb_chip *chip; +unsigned int charge_enable; +unsigned int float_voltage_sel; +int float_voltage_uv;int rc, irq; chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL );
@@ -961,6 +980,18 @@ static int smb_probe(struct platform_device *pdev) "Couldn't get usbin_i IIO channel\n"); } + rc =regmap_read (chip->regmap, chip->base +CHARGING_ENABLE_CMD , + &charge_enable); +if (rc <0 ) +return dev_err_probe (chip->dev, rc, +"Couldn't read charging state\n" ); + + chip->initial_charge_enable = charge_enable &CHARGING_ENABLE_CMD_BIT ; + rc =devm_add_action_or_reset (chip->dev, smb_restore_charge_enable, chip); +if (rc) +return dev_err_probe (chip->dev, rc, +"Couldn't register charging state rollback\n" ); + rc =smb_init_hw (chip);if (rc <0 )return rc;
@@ -995,13 +1026,35 @@ static int smb_probe(struct platform_device *pdev)return dev_err_probe (chip->dev, rc,"Failed to init status change work\n" ); - rc = (chip->batt_info->voltage_max_design_uv - -SMB2_FLOAT_VOLTAGE_MIN_UV ) /SMB2_FLOAT_VOLTAGE_STEP_UV ; +if (power_supply_battery_info_has_prop (chip->batt_info, +POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX )) { + float_voltage_uv = + chip->batt_info->constant_charge_voltage_max_uv; + }else if (power_supply_battery_info_has_prop (chip->batt_info, +POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN )) { + float_voltage_uv = chip->batt_info->voltage_max_design_uv; + }else { +dev_warn (chip->dev,"No battery float voltage; preserving hardware setting\n" ); + goto skip_float_voltage; + } + +if (float_voltage_uv <SMB2_FLOAT_VOLTAGE_MIN_UV || + float_voltage_uv >SMB2_FLOAT_VOLTAGE_MAX_UV ) +return dev_err_probe (chip->dev, -EINVAL , +"float voltage %d uV outside %d-%d uV\n" , + float_voltage_uv, +SMB2_FLOAT_VOLTAGE_MIN_UV , +SMB2_FLOAT_VOLTAGE_MAX_UV ); + + float_voltage_sel = + (float_voltage_uv -SMB2_FLOAT_VOLTAGE_MIN_UV ) / +SMB2_FLOAT_VOLTAGE_STEP_UV ; rc =regmap_update_bits (chip->regmap, chip->base +FLOAT_VOLTAGE_CFG , -FLOAT_VOLTAGE_SETTING_MASK , rc); +FLOAT_VOLTAGE_SETTING_MASK , float_voltage_sel);if (rc <0 )return dev_err_probe (chip->dev, rc,"Couldn't set vbat max\n" ); +skip_float_voltage: rc =smb_init_irq (chip, &irq,"bat-ov" , smb_handle_batt_overvoltage);if (rc <0 )return rc;
@@ -1023,6 +1076,8 @@ static int smb_probe(struct platform_device *pdev)if (rc <0 )return dev_err_probe (chip->dev, rc,"Couldn't set wake irq\n" ); +devm_remove_action (chip->dev, smb_restore_charge_enable, chip); +platform_set_drvdata (pdev, chip);/* Initialise charger state */
Signature · 1 line
2.53.0