Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3260002rwo; Fri, 4 Aug 2023 01:51:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBrvkJLT3qHRn4jXRV8rTr3syNsyonYPxMmbifqNVD6yPLsU27b/DK56nSyiXDqIT8GyRo X-Received: by 2002:a17:907:b16:b0:99c:6fb6:ae7c with SMTP id h22-20020a1709070b1600b0099c6fb6ae7cmr942773ejl.22.1691139103579; Fri, 04 Aug 2023 01:51:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691139103; cv=none; d=google.com; s=arc-20160816; b=Kf24DKF9b/wcHyvuX5moaMNP3FBWso0NlZARETQhgEYtWshCqp5TaqkKKx6TNnxZIL zXeTabSmxrGfwNo4QqdCqoQM3JEEK7odxTMXZuxbDAebEk8Oh8zcH3lj5Jwxccym1A62 JqVQJ4dpoA3t2hRpe/VqzPIJfh/1Yf/ujlaxnVmeKE+PQ/Z0mJcz4G0ex6ayO3nwZsgL oiXATjgW63Puik9BHt7gnywO4ZHS52Oa2frS7+Ri2g871Vszy4ap3HATpk9mHsr9qurL zZk0xfA/H7qbOoEKlTSQWv/MOGqlo1x2CvLsAGaMLDSCnbB6NRZaauU+r6sDzkjez/vi UdRw== 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=GSVTdC1th3Ukx8AgC8lNqpynQmQtELOulnR7M8l/f7M=; fh=DNbb4NWPEEMvR7AYwFrriCdg2PEykd9wula4UccEtoM=; b=EWG3TLmYcGdRI9puLcwYgQoRPdXsDgjRwqWVDfoSWNjk2ThCtyx6JrmEEkwT55ly9z TKmbszYdjcolvXbGiS9WitqmznKV3WlhobyCI0yzsKM+PkIdD3fEWx69DQTxjuKWY7Sy vS1DIIwy0E8ZIjKd/bT/4MEMhfsvp1DAf9d6OySbZwiHRlOPq8OGqR5CuNVxttX5u9vK SG+fUGLMa8kgYBg9Z7Y39j8Uz3+9GwHZyE6L4H6cumHoHS8aOxLZswjvuzLZzmNf2w/3 bSsecGSKe4WmcqknN7gFJQSTmvsBs+2/cBjF+kMvSl1ZLI8W2eckXo7W1Kxt73pQYQOA xaDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flowbird.group header.s=google header.b=KOwPaz7g; 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=REJECT sp=REJECT dis=NONE) header.from=flowbird.group Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jt4-20020a170906ca0400b0098cf1b12715si1273937ejb.581.2023.08.04.01.51.19; Fri, 04 Aug 2023 01:51:43 -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=@flowbird.group header.s=google header.b=KOwPaz7g; 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=REJECT sp=REJECT dis=NONE) header.from=flowbird.group Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232225AbjHDIfV (ORCPT + 99 others); Fri, 4 Aug 2023 04:35:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjHDIfT (ORCPT ); Fri, 4 Aug 2023 04:35:19 -0400 Received: from mail-ej1-x661.google.com (mail-ej1-x661.google.com [IPv6:2a00:1450:4864:20::661]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8433D3A85 for ; Fri, 4 Aug 2023 01:35:16 -0700 (PDT) Received: by mail-ej1-x661.google.com with SMTP id a640c23a62f3a-99bcc0adab4so259638166b.2 for ; Fri, 04 Aug 2023 01:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flowbird.group; s=google; t=1691138115; x=1691742915; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GSVTdC1th3Ukx8AgC8lNqpynQmQtELOulnR7M8l/f7M=; b=KOwPaz7gZkyWZPuu2uMYiRqp4NRH9rSvMOyZmicVUYzhf96luS1dtfsdjKlQ/9wdNK Kg3ZNGMcr8xDjqht23BvMyOFPdrBlVEGnaCBs07jHmJ1btj3A3ZRMn9KJ0M1aA8vrbB3 MnRAHEQW3urPDuCU3wGK/c/nJRezsALhpmZsadtxzMF/dC5LnsdhyvEFukkv1TeFmm0d mJyUeIhfxp5Y5whOrJyyulpKo8G+XmYtNNMVjj4wKJBrssHP7dyXJwzKHPOTSVfSupBy b8F0Gt1qvAMTx8EWz9TTOel4kHY0Y/PxpwQTx62uDtAEyh9VebmWUmg1HlRnvEcnFQeU RL/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691138115; x=1691742915; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GSVTdC1th3Ukx8AgC8lNqpynQmQtELOulnR7M8l/f7M=; b=jJ/Y/6+HQ/4oMSMNftFihUHTpmWThIWkHJYM9xdzg8tB4SgGk89PlZoh4QkZ4O0675 Y06A4YJGMjJGuO0lkDLt+xNPvP4UkQdCpRBUj1RWQUEHk2HVChiUuS1cGibuVpuFJ8bK x9HCyQ3dCBarP3D15bQayyPIcl/YPMxsflQHkRpK0TyE/JJYdV9HntyUiCg+iDrc69Mz Fm2VaqEQ59aCN2Q8a/RdN2Sv9I8vwb6Qa8PowFlKrcePRLPliteKFNDZ8RwDiBOYWsxj PcWw3ZZ/cyJB1zkDKJHBPMdNGs7ttwVosireVj94cGnBve0hErPHYGerBJOpJfOCQHl5 OcgA== X-Gm-Message-State: AOJu0YwmqZqwH5UhHhElgBQLwJMFnqXWBKwUfSEXfclXgxY0d3lEAE6e 4HaIuJsomuVLRdWXfgji5xwEwwEDVzdvz5k/zfYuBPjytafw X-Received: by 2002:a17:906:51c6:b0:99b:d007:67b1 with SMTP id v6-20020a17090651c600b0099bd00767b1mr994884ejk.72.1691138114959; Fri, 04 Aug 2023 01:35:14 -0700 (PDT) Received: from mta1.parkeon.com ([185.149.63.251]) by smtp-relay.gmail.com with ESMTPS id t24-20020a170906065800b00982360305f5sm172071ejb.9.2023.08.04.01.35.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 04 Aug 2023 01:35:14 -0700 (PDT) X-Relaying-Domain: flowbird.group Received: from [172.16.12.154] (port=40918 helo=FR-BES-DKT15120.home) by mta1.parkeon.com with esmtp (Exim 4.71) (envelope-from ) id 1qRqJX-0003QU-T1; Fri, 04 Aug 2023 10:37:39 +0200 From: Martin Fuzzey To: Mark Brown Cc: Support Opensource , Adam Ward , Benjamin Bara , linux-kernel@vger.kernel.org Subject: [PATCH] regulator: da9063: better fix null deref with partial DT Date: Fri, 4 Aug 2023 10:34:30 +0200 Message-Id: <20230804083514.1887124-1-martin.fuzzey@flowbird.group> X-Mailer: git-send-email 2.25.1 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 Two versions of the original patch were sent but V1 was merged instead of V2 due to a mistake. So update to V2. The advantage of V2 is that it completely avoids dereferencing the pointer, even just to take the address, which may fix problems with some compilers. Both versions work on my gcc 9.4 but use the safer one. Fixes: 98e2dd5f7a8b ("regulator: da9063: fix null pointer deref with partial DT config") Signed-off-by: Martin Fuzzey Tested-by: Benjamin Bara Cc: stable@vger.kernel.org --- drivers/regulator/da9063-regulator.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c index dfd5ec9f75c9..a0621665a6d2 100644 --- a/drivers/regulator/da9063-regulator.c +++ b/drivers/regulator/da9063-regulator.c @@ -778,9 +778,6 @@ static int da9063_check_xvp_constraints(struct regulator_config *config) const struct notification_limit *uv_l = &constr->under_voltage_limits; const struct notification_limit *ov_l = &constr->over_voltage_limits; - if (!config->init_data) /* No config in DT, pointers will be invalid */ - return 0; - /* make sure that only one severity is used to clarify if unchanged, enabled or disabled */ if ((!!uv_l->prot + !!uv_l->err + !!uv_l->warn) > 1) { dev_err(config->dev, "%s: at most one voltage monitoring severity allowed!\n", @@ -1031,9 +1028,12 @@ static int da9063_regulator_probe(struct platform_device *pdev) config.of_node = da9063_reg_matches[id].of_node; config.regmap = da9063->regmap; - ret = da9063_check_xvp_constraints(&config); - if (ret) - return ret; + /* Checking constraints requires init_data from DT. */ + if (config.init_data) { + ret = da9063_check_xvp_constraints(&config); + if (ret) + return ret; + } regl->rdev = devm_regulator_register(&pdev->dev, ®l->desc, &config); -- 2.25.1