Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1608496imm; Sun, 23 Sep 2018 07:45:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYFbnWLj6DvFfVeshiE0IiUnb0Gfs1rWL2bwzWJNVWhESfznjUHZQN/IDXS9jlqp0s896kB X-Received: by 2002:a62:89d8:: with SMTP id n85-v6mr6608781pfk.83.1537713945632; Sun, 23 Sep 2018 07:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537713945; cv=none; d=google.com; s=arc-20160816; b=RiGCCfJRollF2u/MJddqUKg4RHPMPa57Uvn8rCJkJLx29wYkfOszp2KiXfuLzSrC2Z rWNtJHvX96LbIvhimnJaqLI14Oe+bq3euqcQAtqkzt5/0CAT8sVL7VdBu6GXobXkTXYS K4Tw41QS/y84hrCHDXr8HumzmYzDT7tpyL3PttpW0cPU16AV87zBI5ChqsWTd8UhdHgN ML6kltsrmKk+4sjqM7rf+7KuzwrAIaIHs0qObMXQ5a4UTeUxNIE2IRDMWG6Qh1lwZJq0 VjTRMNUn+reI66SHMf73r62+5o3WXrvn/rukkNZ4OpIIGQBOOYI4hU5XP8cKb8LaRscU K9nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3ttCP12tU/CEnuitBJKgkwYR3EOm8EPE9UTCWNjlKAg=; b=Cb4Vmu1j6w10DWo5drPsSTDdVvKPIv9MFn2HlyuarcaR2cVqOmAnw7DuAgEHmAjiU9 kuyji7hJ+hpTUAh8ZsXgQeqG1+NoVQQHYwAuIKYL77xG7ma2DQs3NYk7voV344PwfC5B C4yZIj9PHDpxkksCF2ZGiW6FmUnlBNBRQrHxeDpFz28m0ZMJEyXHS/J4N5YBbPZZcbcv Rl+S94j2zX1GBM4g77kT832rO5iXAcQBWg0rShwxyTmZDfIinpHweDLWJdmE9dCN25mh 0ekDvjwH6B0/gnCxuutkQgaauEPh8w6sFScPz7JrAT7mwE4IxiqNp3ZqqFzl3nxJpOUZ oYhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15-v6si31931602plo.284.2018.09.23.07.45.30; Sun, 23 Sep 2018 07:45:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbeIWUnB (ORCPT + 99 others); Sun, 23 Sep 2018 16:43:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58876 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726259AbeIWUnB (ORCPT ); Sun, 23 Sep 2018 16:43:01 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B8AC85A07; Sun, 23 Sep 2018 14:45:19 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 184AF271A3; Sun, 23 Sep 2018 14:45:16 +0000 (UTC) From: Hans de Goede To: Andy Shevchenko , Mika Westerberg , Jarkko Nikula , Wolfram Sang , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: Hans de Goede , linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] ACPI / PMIC: xpower: Block P-Unit I2C access during read-modify-write Date: Sun, 23 Sep 2018 16:45:09 +0200 Message-Id: <20180923144510.4564-3-hdegoede@redhat.com> In-Reply-To: <20180923144510.4564-1-hdegoede@redhat.com> References: <20180923144510.4564-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 23 Sep 2018 14:45:19 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org intel_xpower_pmic_update_power() does a read-modify-write of the output control register. The i2c-designware code blocks the P-Unit I2C access during the read and write by taking the P-Unit's PMIC bus semaphore. But between the read and the write that semaphore is released and the P-Unit could make changes to the register which we then end up overwriting. This commit makes intel_xpower_pmic_update_power() take the semaphore itself so that it is held over the entire read-modify-write, avoiding this race. Signed-off-by: Hans de Goede --- drivers/acpi/pmic/intel_pmic_xpower.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/pmic/intel_pmic_xpower.c b/drivers/acpi/pmic/intel_pmic_xpower.c index 316e55174aa9..9e6ddf2a2d4e 100644 --- a/drivers/acpi/pmic/intel_pmic_xpower.c +++ b/drivers/acpi/pmic/intel_pmic_xpower.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "intel_pmic.h" #define XPOWER_GPADC_LOW 0x5b @@ -180,15 +181,21 @@ static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg, static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg, int bit, bool on) { - int data; + int data, ret; /* GPIO1 LDO regulator needs special handling */ if (reg == XPOWER_GPI1_CTRL) return regmap_update_bits(regmap, reg, GPI1_LDO_MASK, on ? GPI1_LDO_ON : GPI1_LDO_OFF); - if (regmap_read(regmap, reg, &data)) - return -EIO; + ret = iosf_mbi_block_punit_i2c_access(); + if (ret) + return ret; + + if (regmap_read(regmap, reg, &data)) { + ret = -EIO; + goto out; + } if (on) data |= BIT(bit); @@ -196,9 +203,11 @@ static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg, data &= ~BIT(bit); if (regmap_write(regmap, reg, data)) - return -EIO; + ret = -EIO; +out: + iosf_mbi_unblock_punit_i2c_access(); - return 0; + return ret; } /** -- 2.19.0.rc1