Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2286028imm; Thu, 11 Oct 2018 08:00:28 -0700 (PDT) X-Google-Smtp-Source: ACcGV61uVnEpI9C/e6OHHMx2X0qrn0RaaMa1mgyP44SadZVzxj5/S3TfrJxCkUVNZ7QI3JbwrFMq X-Received: by 2002:a63:565d:: with SMTP id g29-v6mr1712939pgm.227.1539270028733; Thu, 11 Oct 2018 08:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539270028; cv=none; d=google.com; s=arc-20160816; b=avhuAgZ0GCfZ9irtkqggj6gP3nojmcQkp/7Hcy0GSuLYRHYBdiuTXVfS/7nOQEbPDp vWvlGJqnYXYMFxg3Od0Stec7O5z7npyXqFD+giA79iriM+Zje8Unch/cVlE9ispJsuEj TXjlTEH4eGJBjdvjit6rJLnef3LkfjaPzQR6Bc02LIrnduuedK1H7CRFIPOmNZypgEav DRXGx+veTqFSqzCH2rRA+8NAnRTno18QzS15l3lyDdioHEkCTDaoP4oCxnpXPWc0Byp/ koemI5B5KwiuVEmDvCod3SfbeiYs2M7ddPdrEf1T3iRYZWEMCVfDMuBWYsd0TlxIGJ5S HyFA== 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=MuGM40dsLPYunJmLJ+7D9VyikfOotuVDOH+g3mEcxv0=; b=Xw9T7N5NnmVb0R3aJrdnGi1iu+ypL5VanUpmvhpJF+5Pe64DucXGTO14YDyv9Svnkc SoxZxShJGz/fk5JfD47gTiccb86uhYNCO+FdgCsZguULYlWZivHUQSPTNRWh24ejpyLv DiEJHYeOyus+vKCqzieszoaFW+bx2/tgVvAh6S+PtdkrYD4XmzEY5jU2dMcZTG+mejEL 67AH4bHrOg3F0fmXn39tqLNunXSnhk5id1ZcoVEYYzdLLwkP6jbKf46TMTpNONEWYut7 c2UqYUZOh/g7ZzXLl6rUz7dYxf5rF2v0NxcVkEge0y8oj+X7I9X+clmqXdpuXW/YxmgH aWKw== 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 m6-v6si29607696pfg.282.2018.10.11.08.00.13; Thu, 11 Oct 2018 08:00:28 -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 S1728686AbeJKV5O (ORCPT + 99 others); Thu, 11 Oct 2018 17:57:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51844 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbeJKV5O (ORCPT ); Thu, 11 Oct 2018 17:57:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1AFE30084CA; Thu, 11 Oct 2018 14:29:48 +0000 (UTC) Received: from shalem.localdomain.com (unknown [10.36.118.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C700764EE; Thu, 11 Oct 2018 14:29:38 +0000 (UTC) From: Hans de Goede To: Jarkko Nikula , Wolfram Sang , Andy Shevchenko , Mika Westerberg , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: Hans de Goede , linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] ACPI / PMIC: xpower: Block P-Unit I2C access during read-modify-write Date: Thu, 11 Oct 2018 16:29:10 +0200 Message-Id: <20181011142911.13750-3-hdegoede@redhat.com> In-Reply-To: <20181011142911.13750-1-hdegoede@redhat.com> References: <20181011142911.13750-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 11 Oct 2018 14:29:49 +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