Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1727666rwd; Tue, 13 Jun 2023 13:17:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5GHoYrdRFgA7RZ6JlKUPpX5DRB5AKSlzWzOAwA6Qf6B4Fm75U1her5zSrfebgxrfrgDama X-Received: by 2002:a17:907:9812:b0:96f:94f1:b0a5 with SMTP id ji18-20020a170907981200b0096f94f1b0a5mr14221426ejc.8.1686687450770; Tue, 13 Jun 2023 13:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686687450; cv=none; d=google.com; s=arc-20160816; b=bl+T+Rl60gV0ivDaDcWBpccvB0y8jlZjPa/zRX2lFHo+/gmUHLnVdN1Byc60AthIJb k5XRPu4/KYjJhHeZw3w053PmAWDshGRS+n10cE5IAB80w9kUtBF5K/0rkhTbaq5SEkrP W+hd9WrxhVTAjMJtx40fCURqc8Wwmaa2KWgsDF1+9Xc24lDLlacxStAkQ69yS61JLiAA GiprWxMf/O9uF1YGUtzGhsDamN//jSPia4q3yu/7QRmIAH85DZP7GFeFvq329GSXuhDf f/RQOxdIGuBO2h5u1QzepeUXvOBS9c+xSKWbjrppAN2WeXn6rajdc1LkRJAX017A7u1m mbWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=H9jTYrOmd8b3J0G9R6tjbL0+izw0TOwkbJOEXGLG4+0=; b=yumQNFa2JF3Rv8fCGAO/jEcA6Yh9MEy/wrN6XSttilNXSUJ562JElL4N7KO3AYmtk9 F5bbsc5aShn04Vfppxv0ZANu8uRo6P9zFiA79chKeiOt7VC4A8nvw8Vl9C8kshaQNgFN 3PV6dk5AW13C0aWYfXBTB86SokIm7ojmupdW9jieJdQuaamAy765czQLV6Sr2FAGvE49 yFXDpnHSBuRG5yETM+C8Aa1mECi/jjQYy3k3U/UgiJ8do/wbq0CXWRBtnWmh33fEm1gv sTmoDQzVMnXhH+KYJvayKwsgRvLUKFWRZrSZlMkCc6BANvgh6h+FKcX+pXaPWvspnvHQ eZzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jxX8Y/Xu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020aa7d0d1000000b005187a3f512csi951631edo.635.2023.06.13.13.17.06; Tue, 13 Jun 2023 13:17:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jxX8Y/Xu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239923AbjFMUH0 (ORCPT + 99 others); Tue, 13 Jun 2023 16:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbjFMUHY (ORCPT ); Tue, 13 Jun 2023 16:07:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AEC61BE8 for ; Tue, 13 Jun 2023 13:07:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 67BE761554 for ; Tue, 13 Jun 2023 20:07:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B1F0C433D9; Tue, 13 Jun 2023 20:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686686839; bh=cBzrkpEp4ssa1s3NzFCpArV7nF8Fv4V6npfoOqtTpFQ=; h=From:Date:Subject:To:Cc:From; b=jxX8Y/XuuLmoPqETf6kyvWegHhkrd9oKxJAY0IB33ftDOjcQkif8z8H7YsKIaIuGG rtL3eWjKloJpg/64Zl2n+V92gOlvbGxc/nSFZull1sypZ09yj/0kfz4hawSv6kk8Ef o0Ca9hLeLPr9zWboEAJhK+29nZUUm8PcrugYjpoy9BsqDhiJarXpJROrhZlXZ8ZRWD JdE3vwIbe4KtgUI0g4yV4uMIePgc2U+Rc3Tw/yTZshbmyicbX7BvHNWQdPTCbD7z0j OU1lyp6yINaHxjW8dON3LLpPrhJxgFdGPOFXdHH6Nf/GF8hznjRsmHtMdFLOa3stYR eR1KkA5ZNXKag== From: Mark Brown Date: Tue, 13 Jun 2023 21:07:16 +0100 Subject: [PATCH] regmap: Check for register readability before checking cache during read MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230613-b4-regmap-check-readability-before-cache-v1-1-b144c0b01ed9@kernel.org> X-B4-Tracking: v=1; b=H4sIAHPMiGQC/x2OywqDMBBFf0Wy7oAxVWx/pbiYjBMz2EaZlD4Q/ 72xy3MuHO5mMqtwNtdqM8ovybKkAvZUGYqYJgYZC5umblzdWQf+DMrTA1egyDQXwBG93OX5Bc9 hUQbCMsEldG3vXI8tWVNyHjODV0wUj+B70fnQq3KQz//Bbdj3H4meuSiRAAAA To: linux-kernel@vger.kernel.org Cc: Mark Brown X-Mailer: b4 0.13-dev-c6835 X-Developer-Signature: v=1; a=openpgp-sha256; l=1295; i=broonie@kernel.org; h=from:subject:message-id; bh=cBzrkpEp4ssa1s3NzFCpArV7nF8Fv4V6npfoOqtTpFQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkiMx2Q1ZDGinfDW7oL7OUbC8y3p4UH2gOvcLAult3 6nq+NsaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZIjMdgAKCRAk1otyXVSH0GSyB/ 4iAasEhoHy5gno6PFoPqaH1wwZlDHzctTNDPwNuGWE6MkKYtf3WMh2xPgEvsPX159CJDD6YrFusacT umaipFoS/CKQJSm5RfLoowk9UA288y6px9MT5KTlENS1CIywkhg/N0qRz3N7qXb1f943NDfiH+iun4 UdlQ8ztw47jI61/6zsIUvqsBSY3pAPg2Qar5/eKkeA2QE7lvcakNadyMuHUGy43MS+Lzv39BJvxDN8 nR3uBITpNQ6iDXmr5M+hrTteJdUj0RP31iMeMS4EDdyv/hhdX9fRPLQQ4S7PU5nmQZqLX0L0vEGYG1 TDT/j/K1PCLSY5AvTvvGdgMITTQVDV X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ensure that we don't return a spurious cache hit for unreadable registers (eg, with the flat cache which doesn't understand sparseness) by checking for readability before we do a cache lookup. Signed-off-by: Mark Brown --- 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 fa2d3fba6ac9..3efbe59ca1a7 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2897,6 +2897,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) @@ -2906,9 +2909,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)) --- base-commit: 858fd168a95c5b9669aac8db6c14a9aeab446375 change-id: 20230613-b4-regmap-check-readability-before-cache-9f658338a5c1 Best regards, -- Mark Brown