Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1365147pxj; Fri, 18 Jun 2021 05:44:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2neqV2FByFkbMdAZiMEizU3hQsTUrN7Cc1CZHZZQtbnMtyRGyHwpyzh5AbvIKQ/X7InKQ X-Received: by 2002:a05:6402:40d2:: with SMTP id z18mr4802689edb.366.1624020250265; Fri, 18 Jun 2021 05:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624020250; cv=none; d=google.com; s=arc-20160816; b=GX3Fu9jTmiSzH62JT8XTggH9Zf4S2fTWgU72vQ0noXmwzouwJ4ndNnPy4ODP/9v3gM f7q4lg/AKFJJUSZ+gbemhH+mxPwIymvuj3jlk+HNI72StCYyc82gIWTfD9v/WTo7Xk8A 6IjCRK9oZSVTJcQIBMAgqJoybzkAYLHnOgYqbVcTH4v5G0j36SQtCAeKV+cEcZIDHa3t wmAA7CAr4kdyhzyq0UN3UMfqtPR/roXKXvnNi8HuoAQJtsC0nNc9XOQ10KTVhpKRbiEA CvAAUzXveBSn5+/6/WJCeDtD2D5N19esd+cELqFIXR8pZP5/4BzfyvOeKCRIqSdT6c5V Z9Qg== 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=BWyuVJCLSIqxuI9COxZ2i3gGZ7eAv0x5rLGAhfv6nSD2kDXX65eFs5LmgKxscUKjbj 6RbaWoYsTiE8rLHmM3qBQTyK5wez+kbKcRnISD5Jk10cZTEuvT6JVU0FhuFo4AhAmomg P0Nh34DWhEcVdmaRW8qQZjl3duLt5PkfJPXy9lAkR3OXwr5hF84WN7KtLmfPMzDHzGB/ ZrlUrU5MkBxD8KZ0uDcN/vdbTrOupzoiW4kPlwg/X9ksxK/50Vco4SnqGVMmEq32nj1H 0qx3dVXUdTWJdFjkl//HhdYWCxi2jxOCyNExeadHZvNMhdGb6BG0IFdzs8OY3e6TX1B9 eE2w== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 cf25si2828254ejb.550.2021.06.18.05.43.47; Fri, 18 Jun 2021 05:44:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S234061AbhFRLi1 (ORCPT + 99 others); Fri, 18 Jun 2021 07:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34356 "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-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDC6FC06175F for ; Fri, 18 Jun 2021 04:36:16 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id f2so10380983wri.11 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=twH9k6DOLMlgFT+Zhw0TI6cUzf02S5ZEiFyWHFIOCzXz2r3pxBlt2etUYBrPB1JciS Xc145LK53nmS1c3gXOsbv+uW2Z+3N0xpCsVAutuKsP7tEKNekBlve1P55nzHkorus5Dl hqmkm/yMaeYivBXkEcaxy2aUlIZYhKrgZwhsIx4KvGNVNLPOFnj5lLD0dvwsVF0nbuG1 oqauTLEZPe9BF7Po2FNc7Jza1y/UFN4IlkQi7yxW0P8dolKZJ8JXsYfC1mhL7itBWgXa dV9Hm/uSAdVySUDpF4OpmBGsyxt4yKF7i6/INvkyUqakQtOZCOhOghZOkYubao7hMPgJ WVSA== X-Gm-Message-State: AOAM531gm18QA6Z7r5t9LcM2+F4K9t8o4OgutZxNkaLyRyjNDksiibm0 MmbWjcx4fjuumG4VsW5QyXU0eQ== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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)) -- 2.21.0