Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp589776iog; Wed, 29 Jun 2022 06:29:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sttsORJLD8rAGY70mb+/JMo/UbT5tCKc7l6T9g873bvoyZG1BGuBdVLbgfWQYmwXzRhXOb X-Received: by 2002:a05:6402:b48:b0:435:728c:d127 with SMTP id bx8-20020a0564020b4800b00435728cd127mr4247035edb.392.1656509378056; Wed, 29 Jun 2022 06:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656509378; cv=none; d=google.com; s=arc-20160816; b=zwSyxoZ/AQ3suDRLAUqLpcXCt03QMKm4nHAQ2TNRmYqCHuleVi136qGwqS/TIxIdGb tkdTbCFmq06tYtNkXAgc3GfMjqAf4Pc8km9nOd3M9AA+J1ys3f4d5kJGfqVF715tKS6R no5cacu/ZSH/1v8kr0br6zJoe/CMVL1iu06abbdAELak0cAOJv68Aq7MYmAJPoEYtd9F GuwojErwU4IltC0hngLf9xvH5IFuws5rOGYE8F+ZtSdaFBi8rkwEpUrWvMIndRuWp40F Cf/9eag7JmueQDkf9uFR57OZp4gyBTekCikYcw9KeASkMwVi3BWXHEQ3N25LcgMpk7TU YxHA== 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=92nHiG72czsDSt8Vv1MxkfjJxISivqdWpiajRhXOz3g=; b=U9RlzIzknerM4bH6vRe9fhJ3ce+/ewVlhD+mZlkZ+kXUawdgAEY7Wi+ZNr3aAk0A5f nDkwWO7ClnBEe6Uuxe17HhE4xPWXX93mHVYCg8XZNdxWwSglSCPU4l89LzFlmSV3aOfk RNNhX3xuNkH8KfaNJ/EiC/OloryCdevZGcyQ5TIsmyDUxu3CeNRJQhPb9o/FFpxwdXnI 4qwYZmCd750ORzYlFgOQ4QgjZ8xHiK9DUPAWAqTomq1L2d1X/5jotAlFWm3S11V3CH26 JOMqaGq+F3uo1uuRfuwBIZSXbYLfKgJ/34Rnj9m4GdM0nebF7TNL2M/ojM4J2A4sImiL p1bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nBVrqAzF; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a0564021e8a00b00435a061d699si23198614edf.588.2022.06.29.06.29.09; Wed, 29 Jun 2022 06:29:38 -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=@gmail.com header.s=20210112 header.b=nBVrqAzF; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232912AbiF2NKF (ORCPT + 99 others); Wed, 29 Jun 2022 09:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbiF2NKE (ORCPT ); Wed, 29 Jun 2022 09:10:04 -0400 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3938C21A2 for ; Wed, 29 Jun 2022 06:10:03 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id z7so11909191qko.8 for ; Wed, 29 Jun 2022 06:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=92nHiG72czsDSt8Vv1MxkfjJxISivqdWpiajRhXOz3g=; b=nBVrqAzFrCHqh+zX1QE6OKR/pKbey1MtqrDn2kCoBsw+z8WdUYOgapk12JytD2jKNM EV8k0OrLS6OEX1G8Dgwy5hURtD5+IE3r55/n4yWuhXG7Gy4EsfH8iLWlqfzrvA+XD2l0 TFGJn+NZE1g1+iiZcZLCZoC5+EkLZXP/RcFVauQjtVfyBVb4t0yNF461RJGleV1IPPHK zHpU7HBWZGCo5zDx9ZpKbcUS6sbyihwM96PA97Fza3idUW53vRYZdmsJDr12N2M78POL TU/fiAq/bPl8tBtkTYLuS+68IjmJc3U0sb5c4BYg3Ua1eEGEF0mMRnf5n9TIkJ/wr08Z XC5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=92nHiG72czsDSt8Vv1MxkfjJxISivqdWpiajRhXOz3g=; b=E7V97WD5FaWoADpcy0izf/BMBUFzZYv8CO64RAqSjDl1HrhdAlOgABr+Yvm5i6Q+j5 s5adWHked8+N9EVwVW55oeT6ovkSIGjGl8SIAwkjRKZ9zDRruTcDXIahB/lpQncPQXY4 kkssO9H5cabToTp0fy7W8RyMtRbFUN4kacPGVMILDlV0qWqj8TgDpEBKZGh4ew/crNre RraeryhhCvNTLbT/Tqf1F+IEBbk9RGV9VhwVZQe5ZWZlNLtqPz1LfRfgaXdSuWEL+6CQ 3HaisL1GTQf6I/t74iBwBCxxUQ4itcdqMOvJIM8WteOLZRJb3SASR5CfiZkRtnWpXNl7 ghkw== X-Gm-Message-State: AJIora+aF0V8Itkzc6G4uqMSWaRmKBsQxv22BFs4LTium3wnzMcf7rZg sjafU2LzA2AvDZ2HRM2Batg= X-Received: by 2002:a05:620a:269a:b0:6ac:665e:1dd8 with SMTP id c26-20020a05620a269a00b006ac665e1dd8mr1913394qkp.636.1656508202059; Wed, 29 Jun 2022 06:10:02 -0700 (PDT) Received: from MBP.hobot.cc (ec2-13-59-0-164.us-east-2.compute.amazonaws.com. [13.59.0.164]) by smtp.gmail.com with ESMTPSA id cj20-20020a05622a259400b002f936bae288sm10751764qtb.87.2022.06.29.06.09.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jun 2022 06:10:01 -0700 (PDT) From: Schspa Shi To: broonie@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: linux-kernel@vger.kernel.org, Schspa Shi Subject: [PATCH] regmap: cache: Add extra parameter check in regcache_init Date: Wed, 29 Jun 2022 21:09:51 +0800 Message-Id: <20220629130951.63040-1-schspa@gmail.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 When num_reg_defaults > 0 but reg_defaults is NULL, there will be a NULL pointer exception. Current code has no such usage, but as additional hardening, also check this to prevent any chance of crashing. Signed-off-by: Schspa Shi --- drivers/base/regmap/regcache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index d0f5bc827978..d8c31c8ac4a0 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -133,6 +133,12 @@ int regcache_init(struct regmap *map, const struct regmap_config *config) return -EINVAL; } + if (config->num_reg_defaults && !config->reg_defaults) { + dev_err(map->dev, + "Register defaults number are set without the reg!\n"); + return -EINVAL; + } + for (i = 0; i < config->num_reg_defaults; i++) if (config->reg_defaults[i].reg % map->reg_stride) return -EINVAL; -- 2.29.0