From patchwork Tue Jul 25 12:49:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326411 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 7BF05C0015E for ; Tue, 25 Jul 2023 12:50:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232158AbjGYMu3 (ORCPT ); Tue, 25 Jul 2023 08:50:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjGYMt7 (ORCPT ); Tue, 25 Jul 2023 08:49:59 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E7C9FB for ; Tue, 25 Jul 2023 05:49:58 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-98377c5d53eso876956066b.0 for ; Tue, 25 Jul 2023 05:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690289397; x=1690894197; 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=hVigPGX//gTdtgmRuslLbiD1/zcY/J9BI9iISd0U4KzwumlLvSTCrKq4TVJCmKI5+Y gzNDIQRzCKFPphY9vbQsCB8Y0OcWy802EvA7wpSi8njOBNCZyNsNx/TovT71NWTTal0M 6zJrn0OCpMUMog1LoXLLbfPPloeuSf5Cq8Uahs3w58Hu2gJWKIe3wuYNrb7kmA1Az+r8 7FksdF0bC/1r8yXmfBqwolspgGX32xjGunx2VBJr1MCnDU3TgC0/DZjGxFrO0qaQHvOl 5etfhfrRaDodt9q7a6NlRCuoNzeq16P4nKo/Z8ODRTBH31SSfxr53sAIi+ClzWSGRUMT jStg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690289397; x=1690894197; 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=BOUH17CmnhGnu0bR7Q/2QLkY+4tFV76xgrZkAfSzzjPFRS2PflCz1pbMT6v63PRd7v 4G2a5c3+m+UY+yMyJXozQJ8LIgC4X0Dq924zPm3wf3BnuValuKSxpBz+8rOJu6V2s6JR jM3moEeX4TZ5U/0NA7D5AiIh9zho3HnOfi4ljg3kkaMLmIG88ISN9YuvcbgAiNFAo2e+ A7qO80q/k/eZk/rYTWN3E7w3IR8EO8COLoRbttalfuBQTVG2+wtaLnd6PaLQBCXCOD2f pTwFI7qmOwt3XyI46zyQ+9PU8EzuzC2dn5M3Pq4HJvRFyPFMU9slw4v/7wX9xO3D+mXm QbKQ== X-Gm-Message-State: ABy/qLafamcueeUbPeefWwiMetM0OwuX7YoHuAx/6gxpJr00QS0HwgeG PX6lycXJgg+5S6FlW9DH8p5Tjriz/hidFbY6CzTadxTh X-Google-Smtp-Source: APBJJlGLU28v87Y58xqBP2PjJL/KhzkfhRXDaTYlF8sJo7esBdIHBy1dZgN9EPWiJakxco6GyTlwTA== X-Received: by 2002:a17:906:2d9:b0:973:d076:67ab with SMTP id 25-20020a17090602d900b00973d07667abmr12076828ejk.42.1690289396804; Tue, 25 Jul 2023 05:49:56 -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 pk15-20020a170906d7af00b00997e8b6eaa1sm8133283ejb.41.2023.07.25.05.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 05:49:56 -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 1/3] pmbus_core: Refactor pmbus_is_enabled function Date: Tue, 25 Jul 2023 14:49:50 +0200 Message-ID: <20230725124954.3824954-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:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326413 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 1E75DC001DF for ; Tue, 25 Jul 2023 12:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231802AbjGYMua (ORCPT ); Tue, 25 Jul 2023 08:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232331AbjGYMuA (ORCPT ); Tue, 25 Jul 2023 08:50:00 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67DA3DB for ; Tue, 25 Jul 2023 05:49:59 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-992e22c09edso802066766b.2 for ; Tue, 25 Jul 2023 05:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690289398; x=1690894198; 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=xD2BSNpw0ozN3thb1dtWBEB8CA/Y2iCKwoB9ihfmKUM=; b=CyA3oOnxu6kKFadEHW0nl87UpGvrgxftxDTDoXqbGMsHE4Cg/jm0vshSVPLmZg+Zed ukEjtajE/L52c49bGBEIAY3AsizeBwaSoGR8qtTAsPBFfcyG2XjT5xl+l8DNURtesPd8 V4D/GiatML/j4CGnL2xwc/VZoPaJRz8MCd2pR8EhgcZKmv6XCnCfQRhRH4XOB33Gzz77 skKwgd7MtV57ot/CuiLGPhuD7SVLTrNUOLWwQmKmzDscrYb2qSHFePgeRlzItlF7HO+h fNXALOL+jVQ2mNzqFcQNFVB58Lz8h6AQv9IJUC9OX3sM18xuNiF+XFh6Y2yYRAp+BL7b ojaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690289398; x=1690894198; 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=xD2BSNpw0ozN3thb1dtWBEB8CA/Y2iCKwoB9ihfmKUM=; b=A4UJkCmpwlzeDNsLNLKLwjgVQHJIFg/Zx+JCNMrlfvqNi1A8EJXSINCj9anof6lrZb 2X7qpnD9guvmM1gIAYARZd1eZHW3LWNLIXkgPXyO5CKZUOqqbybZb9yuWVv4xm1fdneu HPmVh9Qg50CTQwXkqac1kcVxaOC+efwIHPfjda+sgetuNQ3xgdB3dwa1KtKnYEws2mxg d480ewBBATp51cKd67I2TuWQmp21FkNOT5/euuPQGpTnhdNqxakl/CxaUjOHHkXn7BrE z07V6Y1vTfkMeX3Vr8cyguSxrV6caj+I8H3Aiy0aYgPDA7GzwiQr5sw9kU9W+hJSechU 8VIg== X-Gm-Message-State: ABy/qLadqlplgzTeOM3pcsBp5spJGQGTp6i8Imlg0Yk1SwZ/WTIWamc2 LPdGkYz1P5AcammSe1/3AoZNsw== X-Google-Smtp-Source: APBJJlH/tXsXGJIg2N12sB8I8FJLfQp1OsrtZ/qwRqpCJrIY7lSBsnsEl7zMMes9pll+6uW+9uX9kQ== X-Received: by 2002:a17:906:76d0:b0:991:d05c:f065 with SMTP id q16-20020a17090676d000b00991d05cf065mr13329973ejn.52.1690289398013; Tue, 25 Jul 2023 05:49:58 -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 pk15-20020a170906d7af00b00997e8b6eaa1sm8133283ejb.41.2023.07.25.05.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 05:49:57 -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 2/3] pmbus_core: Fix NULL pointer dereference Date: Tue, 25 Jul 2023 14:49:51 +0200 Message-ID: <20230725124954.3824954-2-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725124954.3824954-1-Naresh.Solanki@9elements.com> References: <20230725124954.3824954-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 --- drivers/hwmon/pmbus/pmbus_core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 42fb7286805b..1f7df36c48a8 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; From patchwork Tue Jul 25 12:49:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326412 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 D7B0CC41513 for ; Tue, 25 Jul 2023 12:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232331AbjGYMua (ORCPT ); Tue, 25 Jul 2023 08:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232466AbjGYMuB (ORCPT ); Tue, 25 Jul 2023 08:50:01 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A423013D for ; Tue, 25 Jul 2023 05:50:00 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-99454855de1so808465566b.2 for ; Tue, 25 Jul 2023 05:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690289399; x=1690894199; 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=hYD19a3O4cLr2nNRYtCL9dvjJwOe0PKsrRBMJLYvYmk=; b=GHdE9k1axkZh7NG9FIG7kI8HeFho5+otFcadAxyAUdOWSW7V/XOJ21z5Ifyub4COEC q8laY+zuCtm2eyIecUUCxyBTZE7qfOTVx9oxSEBy/oyDXQiTxtbhRWuGU8oBn6eshgyR A8dG9P0c0KnZVm3X7oE4zOsYB/aZWL6OBhVRzw+6xjNq4csxLPXaQQZShnEDhnJ+B8JU PXQmR6+21kJN2svkUZo0fpfsnIfgJF5VlP+B+n2L0wCT6KitWDDhEeOly03GYkqbgA+Y Rf0plGS60rcTO2CY44aLHydcAEQgamP+SWgUm4R1a2H0QdCZTmGa9IIUSv6tV5wV6njv WCBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690289399; x=1690894199; 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=hYD19a3O4cLr2nNRYtCL9dvjJwOe0PKsrRBMJLYvYmk=; b=Z3yWZi7uOCZEm7MUoBevZLAcE0/0h+n3HkGVrJwWOw+oc5933SnCRDpQC55YyTGInO +0tEfbFiH2IOTQEw7jxyRmQpCCXSFTiR5eqQ3A7JvKEccRoI57hccMfwLRjejwJt49us 018/D/XpNFEXf8MRHjakakhgL8bvwb3Bp8nOs4XQLtq4rfH9DLJf6dhQ0iEEYnbLeKxE emS3yAndVV/qWJb9nFIRIfXLbHm74cLR3/BY10QFRhadDe+jDQFVU2If+gU7A40HrTed y+1xbzYXCM2s/71JgtKZa+VjJBWV3Y2u0Rj8qJibiWOM+w58mikEJGvY09orxHZwqa1l jBOg== X-Gm-Message-State: ABy/qLZj64sw4f0AG2PslNrHmhHmsCjbmVg+YzDest4O2h9Xm2//F4SM OrHQLPVEVcgjaGRjok7LlMe8nQ== X-Google-Smtp-Source: APBJJlEwzKMO5bXsBdqEZDdoyHatzTagNOamwvW7DbUqDMkw8VGIniMLmZmh6oaFuoya9ZGaZgVklA== X-Received: by 2002:a17:907:7819:b0:99b:4790:a4d4 with SMTP id la25-20020a170907781900b0099b4790a4d4mr12653941ejc.38.1690289399222; Tue, 25 Jul 2023 05:49:59 -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 pk15-20020a170906d7af00b00997e8b6eaa1sm8133283ejb.41.2023.07.25.05.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 05:49:58 -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 3/3] pmbus_core: Fix Deadlock Date: Tue, 25 Jul 2023 14:49:52 +0200 Message-ID: <20230725124954.3824954-3-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725124954.3824954-1-Naresh.Solanki@9elements.com> References: <20230725124954.3824954-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 1f7df36c48a8..1151a09243d3 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2946,37 +2946,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)