From patchwork Tue Jul 25 12:54:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F594C001E0 for ; Tue, 25 Jul 2023 12:54:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231516AbjGYMyn (ORCPT ); Tue, 25 Jul 2023 08:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232528AbjGYMyi (ORCPT ); Tue, 25 Jul 2023 08:54:38 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6AF21992 for ; Tue, 25 Jul 2023 05:54:33 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4fe07f0636bso827860e87.1 for ; Tue, 25 Jul 2023 05:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690289672; x=1690894472; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3Puz3ztq+s5PMQIYSFqmtMplo+slwUgkmSW9O9rbzaQ=; b=eOX71mI8ivbPxd47f1eV4r7XwztgvsB/VUt6UiU2TRTzqzn/nnNc5dYBCQ7YDwpwcw 4HBgy5/tA3pr37dG8a8OX60bkNrHIpBqrsLUJw4zccm3bqKV2Lw5vm4RGbwODH7N6Her yiQtddh86DliiC3qSQhIR9Y1vNaY5Gt5CLb1vHwHV9UgJ9kjuPH05HuPeM57qIhIGKAq zs6T3wIBWTz3h8E8FwJ6FFDuoTE9KEJ0yZQQZFzZBrKjF656WagqNBNREbD7l8OcgZj0 jibS2zS5edmrdiyj3AmKMHjH7JmAAn9J894UFTXdqgXFhPnzh3Fk9sKgZqOyodCVziQL W9jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690289672; x=1690894472; 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=3Puz3ztq+s5PMQIYSFqmtMplo+slwUgkmSW9O9rbzaQ=; b=B+1m4s9+lo8GCDi9mzv05A4NUOtUhta0ivP90/Bl/FxoYEDzgcQ+AVEtlgIpfBs5Kp KbpiG7aktVJjNqELi1/tBoC7VutQtGAGmLFv9leuhRs3SYp6uZCeusWSR5+elgPJAMxI sCgpXsBAqoZQEWUsG8YMFSO1XzCqpdGso98b/9bbUQm+xe3oxUWkvb8r4/Nw0lDg164i clHWHdCbxYNQ3A3e66DK7STKSBxc2NIsUjEajLJJl40v8SeeCinBOYCaqS/PS/rSWhue xADU43L70FjU8VatDwhAxiTnIeN1NL+z9mVZNj44ih0IB3rh3nVfyjhX43b4QF9QYkPf Kq3Q== X-Gm-Message-State: ABy/qLZDq3YkPU1xy6J3Uw2FXCAjZi+X4+2FF+pO1/swJNtqf4AYitR0 YQnzDelQG+ORisHWZ4tAubhZPw== X-Google-Smtp-Source: APBJJlHZSFk1xstmzkc7CIM9TH+3PcYrQLyXquXF3/qVEGqAj4CIMfMvldYlGO/C3XlsJKxIowWyAQ== X-Received: by 2002:ac2:4d96:0:b0:4fb:7532:35aa with SMTP id g22-20020ac24d96000000b004fb753235aamr7085307lfe.28.1690289671914; Tue, 25 Jul 2023 05:54:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 05:54:31 -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 1/3] pmbus_core: Refactor pmbus_is_enabled function Date: Tue, 25 Jul 2023 14:54:25 +0200 Message-ID: <20230725125428.3966803-1-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph Refactor the pmbus_is_enabled() function to return the raw status without any additional processing as its already done in _pmbus_is_enabled function. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 55612007f16b5d7b1fb83a7b0f5bb686829db7c7 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index fa06325f5a7c..42fb7286805b 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2768,7 +2768,7 @@ static int __maybe_unused pmbus_is_enabled(struct device *dev, u8 page) ret = _pmbus_is_enabled(dev, page); mutex_unlock(&data->update_lock); - return !!(ret & PB_OPERATION_CONTROL_ON); + return ret; } #define to_dev_attr(_dev_attr) \ From patchwork Tue Jul 25 12:54:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26BC9C0015E for ; Tue, 25 Jul 2023 12:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233344AbjGYMym (ORCPT ); Tue, 25 Jul 2023 08:54:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232343AbjGYMyi (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 B8BC919A7 for ; Tue, 25 Jul 2023 05:54:34 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-52229d3b8c8so3423303a12.2 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=j7+fSza4WtyQXKgVBdcPqP6phgUySguSINk/QwZBldD7MPyxSpBDT1iLPcjbLw3gAS Ofr5pz6xWZHgS//2h8FnfAhQpt5BOoNP8/MvAgHhN0A+++b0DQVihbO/MEMdWOpuOoG6 2lra8FDmmgnbcfmfBbKviJr0EkgjMOAjc9hkxKa1+bfTJcybyGep87vt4uvXiXaeq81d GOD9W53NDcZhLK8TkJdLQJZLIynuFyfGhiZ4ZYNy8EjM5diX5BJo9SSqKGGJ18Odna/r DId6Y9kh5hAprNIGn7czlQRjl/+kEbkCZLFdk6174nAilfcqsHPNvTfNi1Uju8UXvKcl J7TA== X-Gm-Message-State: ABy/qLZ+80tPPIrat3mq26hHX31wmDdf2Hc99LE1lbpFB9PRQVatEoro vGE6Ct5H8u45Kbp2jnN2XGJBcg== X-Google-Smtp-Source: APBJJlFJOFr4Uo7wpRe7n2jDpOndOddkIBxsVclB5xlern0T4yJlEHsPydZm0qieojTKD5j5MFRMyw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@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) From patchwork Tue Jul 25 12:54:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05456C001DF for ; Tue, 25 Jul 2023 12:54:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233298AbjGYMyn (ORCPT ); Tue, 25 Jul 2023 08:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233308AbjGYMym (ORCPT ); Tue, 25 Jul 2023 08:54:42 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE8213D for ; Tue, 25 Jul 2023 05:54:35 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-51de9c2bc77so7813545a12.3 for ; Tue, 25 Jul 2023 05:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690289674; x=1690894474; 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=4MkRYmXmHZ+64hiKvKzZjrtd77nbRk+uqXsZ3jdXGpc=; b=Aj6w7q3BdmsRSLmcTTqeGv9mNeJhH42tnBilSqCOOSWFLWvdjkHlD0pIVf0xJa+31k TMRPxH9UjCWpAwqz1AtCfG+vwK4y3/uFyjk8qNJJes5CjcxtXqCvGKFsEurEPIxQQFi1 MVrYA4S78fJIiJdWGPJfXmb3Pk9fwDz7gHSiX8eQlFzq3UQ7T2/8c+/uHR9mcvuu6Fub xJwCWB1DF+g+xDM7A+k01oqJWMubV53tEKmBPiKHDx1ZKZOUQEMZcve4aOxaYDXDTXC8 FuHftBsSLCQ62+1Pj1BQdZb/exlYTUWkhNkoFeeVY8DLGpJ0mUEf0VcuqX5Kue/ehUCL 4Uxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690289674; x=1690894474; 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=4MkRYmXmHZ+64hiKvKzZjrtd77nbRk+uqXsZ3jdXGpc=; b=VkFhyECO2LtJNeDP0dDKUQlBAxYBWhWBQHZiUR2V7YBvuXhPHEYBV3fgw+y3qlBCms luOYLKCpAFMOtC2+K7Kvbw1a4QxHHzPScGLX4N6XE8ujq3BsaMaAIcgyQXaG3pP44LYt //x42iOilIdo+Q20W9ayBclhGXmLj25QleBjcABietKyJ343y4kb0TTHZAkVG3ereE6v CMRvovotrRGGEfKNmAumbSiK23uCr3Jzfk3sZmybM79q8gdZLIc4CYltHQMKnX29nwh+ ztTbODplIJHSCLvn66eUqSZ2OH73XYz5uEwBrzabb0itJE6V+oB9U8fLVDEMqSykDOvj QSmw== X-Gm-Message-State: ABy/qLa0Ex1V83XMxR7Zyw5zPECI1yu/107wlS1VsKjLaN4W1oKgAR5K nKO1rzmVbpEnj/9OzFfuHUehpw== X-Google-Smtp-Source: APBJJlFArk8UU2wj3uy9zsuNg0zcth6a3PvBukhgkt5QwJIOzNGUf7EkojPwDZBDoVnAknWTu6SFXw== X-Received: by 2002:a05:6402:645:b0:522:2111:105d with SMTP id u5-20020a056402064500b005222111105dmr7394161edx.20.1690289674437; Tue, 25 Jul 2023 05:54:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 05:54:34 -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 3/3] pmbus_core: Fix Deadlock Date: Tue, 25 Jul 2023 14:54:27 +0200 Message-ID: <20230725125428.3966803-3-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 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph pmbus_regulator_get_error_flags() will also acquire the update_lock, thus unlock the mutex before trying to lock it again from within the same thread. Fixes a deadlock when trying to read the regulator status. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus_core.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 30aeb59062a5..42f4250c53ed 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2949,37 +2949,27 @@ static int pmbus_regulator_get_status(struct regulator_dev *rdev) mutex_lock(&data->update_lock); status = pmbus_get_status(client, page, PMBUS_STATUS_WORD); - if (status < 0) { - ret = status; - goto unlock; - } + mutex_unlock(&data->update_lock); + if (status < 0) + return status; - if (status & PB_STATUS_OFF) { - ret = REGULATOR_STATUS_OFF; - goto unlock; - } + if (status & PB_STATUS_OFF) + return REGULATOR_STATUS_OFF; /* If regulator is ON & reports power good then return ON */ - if (!(status & PB_STATUS_POWER_GOOD_N)) { - ret = REGULATOR_STATUS_ON; - goto unlock; - } + if (!(status & PB_STATUS_POWER_GOOD_N)) + return REGULATOR_STATUS_ON; ret = pmbus_regulator_get_error_flags(rdev, &status); if (ret) - goto unlock; + return ret; if (status & (REGULATOR_ERROR_UNDER_VOLTAGE | REGULATOR_ERROR_OVER_CURRENT | REGULATOR_ERROR_REGULATION_OUT | REGULATOR_ERROR_FAIL | REGULATOR_ERROR_OVER_TEMP)) { - ret = REGULATOR_STATUS_ERROR; - goto unlock; + return REGULATOR_STATUS_ERROR; } - ret = REGULATOR_STATUS_UNDEFINED; - -unlock: - mutex_unlock(&data->update_lock); - return ret; + return REGULATOR_STATUS_UNDEFINED; } static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page)