Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4469709rwo; Tue, 25 Jul 2023 06:38:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlENEphFlWfZklYvqB9X181757oEJ3p8N3xouQ5PCjIcWwlcEJ93qGTgFH27SrbG9puBzqoQ X-Received: by 2002:ac2:5b1c:0:b0:4f8:71bf:a259 with SMTP id v28-20020ac25b1c000000b004f871bfa259mr6147678lfn.67.1690292318628; Tue, 25 Jul 2023 06:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690292318; cv=none; d=google.com; s=arc-20160816; b=cGooaTeCLwEB9xAjBHqps+aUo6pNEELKLFT3+taODaQhvks2mM2SxB4yuW0J2nwVmN bCXxG2YbuGGtAX7PU4kHvvDmzm2XYPC3K/UZ26cPCOS5xDL4JbsbHhDcaC1LyhsJzUcG nBVajrwxcRwoZnu8LveSr0bet4hGCPyseEndYH1RkBuYOvvXKVQ3/QPwJbmPLLNLCHMj RiLiU6pQMwzHTADwC5RgcWQySlimw3cqjz1KmP6+/vzohUZDCLwh6uZq76y8M9DKTmCG oE0ZQN+S3oN9DlY0HJ4oMueBBjHKWwg8pd/1AI2fFkSt+CxMrD3akF4w/w3pyzuNijnm uEKw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EaZID9rRMTJ2nmqmshf6LreUn/mdy/eKyS3ZjSfkijA=; fh=Sy2DcC8iBcoj93plRSksEF0esK794/0rw7KBx0/+VmQ=; b=Y4sn/Ww908/GX9cDNdhMxmUZSxHY76+UQX54z/PHObaR6fXLQfs5ZkWZfIWY6iEcS0 RWxz3SbSeBI6WpLG6x2DwBxrIk9ciLM2lQNwMu2DMshgfMzVpptia9E6oNUf18g+xGDf M0XO8wBCaw+tlIqSPZTt87U76SGTLwQhRLdS8nxhUyA+GKUjojA91PZ953b5E/1osNBN fl45EjJjAX4EU3gtE4lU2q3XmSI8Vk9529U/hcUyvCJHatbc8PKKbjA3ZVPa0+PPaYnX V5N4s5RdvcLESMYU8ATH4sH1UUEgpol9kgUODQrUCSErKt0KvfndXDvNIXTR57WFv/Bk 5MYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=QSQREnbb; 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=9elements.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b24-20020aa7d498000000b005222bc37cf7si3327656edr.232.2023.07.25.06.38.14; Tue, 25 Jul 2023 06:38: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=@9elements.com header.s=google header.b=QSQREnbb; 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=9elements.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232326AbjGYMyq (ORCPT + 99 others); Tue, 25 Jul 2023 08:54:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233146AbjGYMyi (ORCPT ); Tue, 25 Jul 2023 08:54:38 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8F3419AD for ; Tue, 25 Jul 2023 05:54:34 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-51d95aed33aso7822058a12.3 for ; Tue, 25 Jul 2023 05:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690289673; x=1690894473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EaZID9rRMTJ2nmqmshf6LreUn/mdy/eKyS3ZjSfkijA=; b=QSQREnbbcdT7o53ADS7jLKT3qpIMWfe8RoV5g6qY46jVm0R51waOSQqdRJg0ApFLMm SQYG6EayMQTwqlWpmU/lCKee37xrNSTeHtIpw9NCMV4SATK1rkGVEPq8k/5tsjY3gpOf FlVysqLRBLFbcyquWxI4A695NSz8VIYItgUMNqAFzOsBu5ecSTzuE7/S1BKtb7ifrwmk uBpYecLbeVg9ZYL3632aUsWqOn8nxHMLI3mA7YztEdx8GJ3oSL7MFd6WvZgegSVn9QKZ Grj7heTImBj3d7hyFxKbpD0/MEJz3K0Fgh37yVJj1Se8w4MmuzOqKM6MRf4ViOM5aRpL Vdtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690289673; x=1690894473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EaZID9rRMTJ2nmqmshf6LreUn/mdy/eKyS3ZjSfkijA=; b=SSS6OUG7mywj1bJ8GtvvJzj1R/BQKe+hAeUPyngqvV+VwEUwjJO9W2ZPvd8As/s8AM C2IubvhW6AupM7ffTc0CjYKXh+gZImYCjVP4yWUi2l5bVNZnuU9s1HpKCkEqKvCIVSlI Eo8G/h5YMMWQu2l7e1XY2cXeG+kFGs0FEnomECFz2t41TFViIR/OXnkbZ4ffaYoWl5Im D1vLXtUNhFttlbvOrcyJh5pv2C7SWam52E+ih6Cjjp3joPl1t9i1G1QBNmGEYhXBZ7eO OaWa4HGKVytXr1c+24WZCjEt8T6cGhnvzCOS7PwsxKBTCXNnXtJrJOO4TiEgUNLKCA4N 9XGQ== X-Gm-Message-State: ABy/qLY1QQjVLFjTnIFeMMrHr04aWg++ZPFmvsc+MoyAUejkcfNQ7PFE ehfHXEq9Y5ed9NSHnvQWrLncUX/Rj525JhUvDm0B0ZXn X-Received: by 2002:aa7:d354:0:b0:522:2b76:1985 with SMTP id m20-20020aa7d354000000b005222b761985mr4711832edr.2.1690289673250; Tue, 25 Jul 2023 05:54:33 -0700 (PDT) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id u11-20020a056402064b00b0051dfa2e30b2sm7516682edx.9.2023.07.25.05.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 05:54:32 -0700 (PDT) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare Cc: Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] pmbus_core: Fix NULL pointer dereference Date: Tue, 25 Jul 2023 14:54:26 +0200 Message-ID: <20230725125428.3966803-2-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725125428.3966803-1-Naresh.Solanki@9elements.com> References: <20230725125428.3966803-1-Naresh.Solanki@9elements.com> 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_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 From: Patrick Rudolph Pass i2c_client to _pmbus_is_enabled to drop the assumption that a regulator device is passed in. This will fix the issue of a NULL pointer dereference when called from _pmbus_get_flags. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- Changes in V2: - Fix build error. --- drivers/hwmon/pmbus/pmbus_core.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 42fb7286805b..30aeb59062a5 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2745,9 +2745,8 @@ static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[] }, }; -static int _pmbus_is_enabled(struct device *dev, u8 page) +static int _pmbus_is_enabled(struct i2c_client *client, u8 page) { - struct i2c_client *client = to_i2c_client(dev->parent); int ret; ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION); @@ -2758,14 +2757,13 @@ static int _pmbus_is_enabled(struct device *dev, u8 page) return !!(ret & PB_OPERATION_CONTROL_ON); } -static int __maybe_unused pmbus_is_enabled(struct device *dev, u8 page) +static int __maybe_unused pmbus_is_enabled(struct i2c_client *client, u8 page) { - struct i2c_client *client = to_i2c_client(dev->parent); struct pmbus_data *data = i2c_get_clientdata(client); int ret; mutex_lock(&data->update_lock); - ret = _pmbus_is_enabled(dev, page); + ret = _pmbus_is_enabled(client, page); mutex_unlock(&data->update_lock); return ret; @@ -2844,7 +2842,7 @@ static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flag if (status < 0) return status; - if (_pmbus_is_enabled(dev, page)) { + if (_pmbus_is_enabled(client, page)) { if (status & PB_STATUS_OFF) { *flags |= REGULATOR_ERROR_FAIL; *event |= REGULATOR_EVENT_FAIL; @@ -2898,7 +2896,10 @@ static int __maybe_unused pmbus_get_flags(struct pmbus_data *data, u8 page, unsi #if IS_ENABLED(CONFIG_REGULATOR) static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) { - return pmbus_is_enabled(rdev_get_dev(rdev), rdev_get_id(rdev)); + struct device *dev = rdev_get_dev(rdev); + struct i2c_client *client = to_i2c_client(dev->parent); + + return pmbus_is_enabled(client, rdev_get_id(rdev)); } static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable) -- 2.41.0