From patchwork Fri Jun 18 11:35:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 463041 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1382170jae; Fri, 18 Jun 2021 04:36:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2J91cYJAoK101IklNSHFbPgjcRHpgWZIG8XDKJ9JZfeBwwWZFSjIGTVPwvMjtiMVq1aSb X-Received: by 2002:a17:907:7717:: with SMTP id kw23mr3410901ejc.476.1624016178318; Fri, 18 Jun 2021 04:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624016178; cv=none; d=google.com; s=arc-20160816; b=IAKxjn3iPuzzAeKu+mOtSz9z5I3fMkspkKuIBHadzWWxFVFKB02FVlVP0f+QY5Xeau 1KTMrwO9CBELie0HEANFukfqlnY97bLQMHa5HV4C8edFVM158Myjhy/gOejKnCyPYIwz wgkwif5jp7J8WzfMJg8UCX0YE2kWr7T9qInCD6PnBstZP8iV27mmp06FqrJLE9IiUwNG yvH8ATVmemwYrEp7N2peWcpIWxFIgOqRUtu4sNI/L4kEhKXQyAlaxG7riKJdXgeAuFq6 jp4riK4ACQtY0ldleHNZulLkOot1Wnx4Joe+fbnQXe2TOhGh5jtjSptnj/rlgW+ZacPp BWyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Lud/fYFD+N/SWgHkdFFeYBIaF2nobhuT1e/M1H5atWU=; b=DwLbc5DCQRthnnQz5aFDeYECusgauuXlNMIpgbbceYwnqUx9mZZQa4zCMTBfw1s6xy vT84/RmznEUSzTDpuFgbKY5LI8ZNvwQ/0EseWQmokWU+C9Fz+LciTlAbMUdwFTqB4B/A b7XJTzXj2lw7X3ofg0fQSWQHk+e+XXOGqzar/cAASUjqalbKnv4SQ9ZCJ1Lo+VI25ir1 5DMvcpBIrje4hLw/WCtznWXVGPDh1kT/N9L/65nr/Xia4DUz+NG446KX9g1ACCu9oCsg IIcRwSdDwvu0pTK+O5EioBfkPXazmlG9/pBDybTRlDLtKaoSidpXWhVCMPs69WBkMY33 q2AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IfePwxiJ; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 6si2190448eje.471.2021.06.18.04.36.17; Fri, 18 Jun 2021 04:36:18 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IfePwxiJ; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234051AbhFRLi0 (ORCPT + 12 others); Fri, 18 Jun 2021 07:38:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbhFRLi0 (ORCPT ); Fri, 18 Jun 2021 07:38:26 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC904C061574 for ; Fri, 18 Jun 2021 04:36:16 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id z8so10387138wrp.12 for ; Fri, 18 Jun 2021 04:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Lud/fYFD+N/SWgHkdFFeYBIaF2nobhuT1e/M1H5atWU=; b=IfePwxiJUb69H2NzVNd2Ays4KLKF1AZQk3rHb1BkYzAIjK4udY25MQFjF0lUFH+LYd v13BjDDrUyuKiFTN6CiCxcjSVW5gjDvBLkpYnn0ug/vEHXNZJb8Hu8qrTDJ77T8GhN8o Sap+69mBmZX6w1pco3jqWQnfPOflCHNT8zK8oQQl+2B8IPYvDuLFgYvRLbni8VOaLX15 MnsbtbRdg1TW+fFvMO6zAhuaVVqBaP8ZI/Ck+d7gJKXYHg48lP+EaVZg2+K9TjXbI45E AUIhjCAc75Ra/NHv9m1ENy+n0132yJ3jUPgkCsJ5Wqqw2S8HwW3XKgEqI0ObNKMzngR1 T2pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Lud/fYFD+N/SWgHkdFFeYBIaF2nobhuT1e/M1H5atWU=; b=jaTyqeCyxpYHUBg7WGs87u/GyE6udeRxUJiqt2l+rq7IkCsZaQn7cjwIT8lhmUiZ3s BUOKS2KcwNFLphvoJA01NISk5C79qdnEzsE1FhSzvoE8/NrZxNgqhAhJ/i/DXxreWIgI PJ6PxewYRVRkUbKw1ilf7GtZ3mS7elRweaAw1+v/IVOMejiizZb9jjNlD5uPXsDCvYah b3FYMboyBHxeYzXKn+uapBi0UjGLsjfQSnnazIYBXkWeCl9gWZJErvY7MxcUZVM996gR yj9gOqaeyQ8+88REBxahuZ+mLgw0BJ56BkY7NdOZdnPvEzEpXiNHvqJbQyaKrhGg6oTG 7LXw== X-Gm-Message-State: AOAM533HSidOzUQUloithiIjElr8vaNKCfM0HuBynS68G6o3Lc4xRmN5 s3w5lEHIIAGPxZAPcYwhD/ZVAw== X-Received: by 2002:adf:d1e4:: with SMTP id g4mr11903148wrd.405.1624016175378; Fri, 18 Jun 2021 04:36:15 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id a1sm10977602wra.63.2021.06.18.04.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 04:36:14 -0700 (PDT) From: Srinivas Kandagatla To: broonie@kernel.org Cc: srivasam@codeaurora.org, rafael@kernel.org, dp@opensource.wolfsonmicro.com, linux-kernel@vger.kernel.org, Srinivas Kandagatla , stable@vger.kernel.org, Marek Szyprowski Subject: [PATCH] regmap: move readable check before accessing regcache. Date: Fri, 18 Jun 2021 12:35:58 +0100 Message-Id: <20210618113558.10046-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The issue that I encountered is when doing regmap_update_bits on a write only register. In regcache path this will not do the right thing as the register is not readable and driver which is using regmap_update_bits will never notice that it can not do a update bits on write only register leading to inconsistent writes and random hardware behavior. There seems to be missing checks in regcache_read() which is now added by moving the orignal check in _regmap_read() before accessing regcache. Cc: stable@vger.kernel.org Fixes: 5d1729e7f02f ("regmap: Incorporate the regcache core into regmap") Reported-by: Marek Szyprowski Signed-off-by: Srinivas Kandagatla --- drivers/base/regmap/regmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.21.0 diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 297e95be25b3..3ed37a09a8e9 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2677,6 +2677,9 @@ static int _regmap_read(struct regmap *map, unsigned int reg, int ret; void *context = _regmap_map_get_context(map); + if (!regmap_readable(map, reg)) + return -EIO; + if (!map->cache_bypass) { ret = regcache_read(map, reg, val); if (ret == 0) @@ -2686,9 +2689,6 @@ static int _regmap_read(struct regmap *map, unsigned int reg, if (map->cache_only) return -EBUSY; - if (!regmap_readable(map, reg)) - return -EIO; - ret = map->reg_read(context, reg, val); if (ret == 0) { if (regmap_should_log(map))