Unverified Commit 85901a0d authored by Rong Zhang's avatar Rong Zhang Committed by Ilpo Järvinen
Browse files

platform/x86: ideapad-laptop: Protect GBMD/SBMC calls with mutex



The upcoming changes for Rapid Charge support require two consecutive
SBMC calls to switch charge_types. Hence, a mutex is required.

No functional change intended.

Signed-off-by: default avatarRong Zhang <i@rong.moe>
Acked-by: default avatarIke Panhc <ikepanhc@gmail.com>
Link: https://patch.msgid.link/20251105182832.104946-3-i@rong.moe


Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent 06c129ca
Loading
Loading
Loading
Loading
+56 −35
Original line number Diff line number Diff line
@@ -159,6 +159,7 @@ struct ideapad_rfk_priv {
struct ideapad_private {
	struct acpi_device *adev;
	struct mutex vpc_mutex; /* protects the VPC calls */
	struct mutex gbmd_sbmc_mutex; /* protects GBMD/SBMC calls */
	struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
	struct ideapad_rfk_priv rfk_priv[IDEAPAD_RFKILL_DEV_NUM];
	struct platform_device *platform_device;
@@ -456,8 +457,7 @@ static int debugfs_status_show(struct seq_file *s, void *data)
	struct ideapad_private *priv = s->private;
	unsigned long value;

	guard(mutex)(&priv->vpc_mutex);

	scoped_guard(mutex, &priv->vpc_mutex) {
		if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value))
			seq_printf(s, "Backlight max:  %lu\n", value);
		if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value))
@@ -482,11 +482,15 @@ static int debugfs_status_show(struct seq_file *s, void *data)
			seq_printf(s, "Touchpad status: %s (%lu)\n", str_on_off(value), value);
		if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value))
			seq_printf(s, "Camera status:   %s (%lu)\n", str_on_off(value), value);
	}

	seq_puts(s, "=====================\n");

	scoped_guard(mutex, &priv->gbmd_sbmc_mutex) {
		if (!eval_gbmd(priv->adev->handle, &value))
			seq_printf(s, "GBMD: %#010lx\n", value);
	}

	if (!eval_hals(priv->adev->handle, &value))
		seq_printf(s, "HALS: %#010lx\n", value);

@@ -623,9 +627,11 @@ static ssize_t conservation_mode_show(struct device *dev,

	show_conservation_mode_deprecation_warning(dev);

	scoped_guard(mutex, &priv->gbmd_sbmc_mutex) {
		err = eval_gbmd(priv->adev->handle, &result);
		if (err)
			return err;
	}

	return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result));
}
@@ -644,6 +650,8 @@ static ssize_t conservation_mode_store(struct device *dev,
	if (err)
		return err;

	guard(mutex)(&priv->gbmd_sbmc_mutex);

	err = exec_sbmc(priv->adev->handle, state ? SBMC_CONSERVATION_ON : SBMC_CONSERVATION_OFF);
	if (err)
		return err;
@@ -2008,15 +2016,22 @@ static int ideapad_psy_ext_set_prop(struct power_supply *psy,
				    const union power_supply_propval *val)
{
	struct ideapad_private *priv = ext_data;
	unsigned long op;

	switch (val->intval) {
	case POWER_SUPPLY_CHARGE_TYPE_LONGLIFE:
		return exec_sbmc(priv->adev->handle, SBMC_CONSERVATION_ON);
		op = SBMC_CONSERVATION_ON;
		break;
	case POWER_SUPPLY_CHARGE_TYPE_STANDARD:
		return exec_sbmc(priv->adev->handle, SBMC_CONSERVATION_OFF);
		op = SBMC_CONSERVATION_OFF;
		break;
	default:
		return -EINVAL;
	}

	guard(mutex)(&priv->gbmd_sbmc_mutex);

	return exec_sbmc(priv->adev->handle, op);
}

static int ideapad_psy_ext_get_prop(struct power_supply *psy,
@@ -2029,9 +2044,11 @@ static int ideapad_psy_ext_get_prop(struct power_supply *psy,
	unsigned long result;
	int err;

	scoped_guard(mutex, &priv->gbmd_sbmc_mutex) {
		err = eval_gbmd(priv->adev->handle, &result);
		if (err)
			return err;
	}

	if (test_bit(GBMD_CONSERVATION_STATE_BIT, &result))
		val->intval = POWER_SUPPLY_CHARGE_TYPE_LONGLIFE;
@@ -2293,6 +2310,10 @@ static int ideapad_acpi_add(struct platform_device *pdev)
	if (err)
		return err;

	err = devm_mutex_init(&pdev->dev, &priv->gbmd_sbmc_mutex);
	if (err)
		return err;

	err = ideapad_check_features(priv);
	if (err)
		return err;