From patchwork Thu Aug 22 07:20:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13772882 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 658B9C531DF for ; Thu, 22 Aug 2024 07:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0OkXJystyHFO3QqFrhx1xRYATCv0SLvRjJj6gA62TPk=; b=EyXG8VnfeOycKvekIxXKurEsKb hrlmEvdAnPvqgXRjPQz5WcvvKGwgTDCeorl7FrOAXXFt++gNcUkJjm3GReqpYLXjfUY5xveF4n7UG +EQE16wzQQsge0w0SlmoI3DhRMAFLAHdDOXpbPTAy1udQ8TpKygsQ+FXHWz53svp0QqGotVuFbqKy MWSPGbpEh2NDhlogPq7h6SiWn3KfVJf1E511k3Ega6xiL8IEyr6fHCV9mdbkcAs/Zd+ZFDnZNkfVv JvCQr/qrdEWuCHkdXAEiIs79IfdJUiEoISgSYIGi+DD76UIA2E525pSC4vSJOSZ4V3KVN4wHEqblJ jvOl2WNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh2Ft-0000000BsHU-2f72; Thu, 22 Aug 2024 07:29:13 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh284-0000000BpzP-1X7E for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 07:21:11 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-27010ae9815so307975fac.2 for ; Thu, 22 Aug 2024 00:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724311266; x=1724916066; darn=lists.infradead.org; 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=0OkXJystyHFO3QqFrhx1xRYATCv0SLvRjJj6gA62TPk=; b=KCQr6Y0zpzC/RmKm2AazAMvs/vpIlWzTfT7QOQHy+LVtQMqtODRFWswOzQROpw3rpW yfySR7ClT975rC1qN49a5SrKfVO9Bz6aL6XO/WGaQ3woLQsvQHuFBmXDfb2CxBdNsrF6 3IqjpWXgTtR7N1Fdy7v37JGsDSyO30b9SCo1s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724311266; x=1724916066; 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=0OkXJystyHFO3QqFrhx1xRYATCv0SLvRjJj6gA62TPk=; b=VoNQBGYxTeitE27P/+JSaPLHDhDTGzA+vMlEe2QVzB5rx1uvm2O7Tp58t3vSh0rg0l s4uDCKmywiOQJKQ6s21TS2Dt9XTqSJLhl7BxAs29l5pTDXiYeyb4OptZOEZDQGnE3oMv w1x8mCVGk/fXfH0CcP/v4td6kQuFdfkzwWxnT09Hnt1GFauHPMvhNFgZBHq/I574Y493 HxjAciYyxk9qTd9AFz/bDRvpvFhnFkEuj/BRcMQ5JZlSk1tL5gdBPBdzEXc+N+hr7Zc+ Gm8jLc1yEyghjO9KHbFnUvSDwFlQRYzGK06+LHyfbliiguzyi8wVGKYb1jIfM7aOVCXm eopg== X-Forwarded-Encrypted: i=1; AJvYcCXk6gxvipwEytndpbCGiRY+Jxf/JQ95MolKhAB5YF/Y2CR2omnIk49Xq3clUA2Sp6EyKK9gdtdFolIkN96RqqZ8@lists.infradead.org X-Gm-Message-State: AOJu0YzXyKf6vmdkJzzFDa29c6XtDFKMaOhXqR8D88AGx9EUaMQD0aHD NTxmP1JxucJDLI1uWl8M5XddaThzIWUnEyGhyegnyJvaJJDREcPe4gtX70A3zg== X-Google-Smtp-Source: AGHT+IFzUCqhCkTr+YqoZpsRxb513kbI0DI/K30PqGR1wgWwO2DPHl2WC1ed/qu4VuxElP0+ie671w== X-Received: by 2002:a05:6871:1c6:b0:25e:7a1:ea8f with SMTP id 586e51a60fabf-273cff9bceamr1248838fac.47.1724311266536; Thu, 22 Aug 2024 00:21:06 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8470:6a67:8877:ce2c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ad6e8e9sm615901a12.86.2024.08.22.00.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:21:06 -0700 (PDT) From: Chen-Yu Tsai To: Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] regulator: Clarify error message for "id == NULL" in _regulator_get() Date: Thu, 22 Aug 2024 15:20:44 +0800 Message-ID: <20240822072047.3097740-2-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240822072047.3097740-1-wenst@chromium.org> References: <20240822072047.3097740-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_002108_615597_809FE443 X-CRM114-Status: GOOD ( 15.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The original error message simply said "get() with no identifier" without any context as to what was requested or what device the request was related to. The only thing the user or developer could do was grep for the message in the full source tree. Amend the error message to be more specific, and also use dev_* to associate the error message with a device. Signed-off-by: Chen-Yu Tsai --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 7674b7f2df14..9029de5395ee 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2183,7 +2183,7 @@ struct regulator *_regulator_get(struct device *dev, const char *id, } if (id == NULL) { - pr_err("get() with no identifier\n"); + dev_err(dev, "regulator request with no identifier\n"); return ERR_PTR(-EINVAL); } From patchwork Thu Aug 22 07:20:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13772881 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 891F9C3DA4A for ; Thu, 22 Aug 2024 07:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3scZTUqJnjgMpybUwcFhKq0rNyJDiP6vw8cgGHLTR6o=; b=vVOd3hpYAb3nx7yFoMpxHkzzVv 3lT1rk/bKMIneaVc9SJgMcqyqp+G0wpuCgWxUTpKbBsFaunNH1E/4/K2lN7BVL142yYTDInL6jGIb Tpm15vZ5XnBuCiRjRnExWi/GC8/4AVxNyhBfv5BjOdR2CIoaTyCYwEGcDUmmwpsW0s/5zlnxrIsKO e9xwmQr6S8FbBVq588xloaWdT7b43r6jGiPWRtR3CfH7Xgl+fn+xQkmvZNJI4JbOyxZ332e4VULBt z0HTOEHtnOXTP/TtZ77AuzgqoCpDlU05YgEnYLa8Rp4Kx/4kjGi/+J2O/bo9LrAbaVZXhw6AZ7CPi WrRFkjIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh2FC-0000000Bs3V-2ujG; Thu, 22 Aug 2024 07:28:30 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh285-0000000Bq17-1o09 for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 07:21:11 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-7b0c9bbddb4so356539a12.3 for ; Thu, 22 Aug 2024 00:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724311268; x=1724916068; darn=lists.infradead.org; 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=3scZTUqJnjgMpybUwcFhKq0rNyJDiP6vw8cgGHLTR6o=; b=aLGQpL9KbU6pYLlcW2LSDQ+HY/dkMYKIosyYAngU+sD5JEcucKp6NgzsC0C6TLiYqg p+osS5OUoNhZ/ebKCohNhKAupOEQLxWdCriWZSSdasqf1ymMhp4tt9GLEtLwmcDU0poG jTEIYRw3LAMtXDMUkkqKcAkiuQsuHzymASzzk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724311268; x=1724916068; 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=3scZTUqJnjgMpybUwcFhKq0rNyJDiP6vw8cgGHLTR6o=; b=Ylosq/T/ddn+Uluudw1GP3URJ6eZcwffhhQ0GJMvOSMVuLfGRz+2jHQEF2y2J18ess OdCVNaFIPn+XXBFPskHHMOI1wvwcMiJSGOrca8nHFZyCKRyCS+XIbzpl52UX0jyJ4YS/ mLOEXiys0R3VmsKX8tSNNRJml/NhLCWjifEzRGEFQByMYdqPWc4ogDvO6wfBRdU4iM1K cUNDgXYL9kgXc8SDBocHyFQcjUBmiJ40/7jHmJ3GoMlHNAyx8fOwwoQZ5ob2k86z4OYd la+XmnpG3L1yx9Lrf8HXYL7XKYM+DfdbQWfhIMPObh4mr84ZfPqXPYhGFwuq6eEc0Rgb ibxg== X-Forwarded-Encrypted: i=1; AJvYcCVHOfFfHYcx+/uptNz38ArCKnTaZMNReXvuWC0k67KjF7tIBkKxxo5IQpI7Naoc0WfprGu2Ngt/d+uzMx6IINDs@lists.infradead.org X-Gm-Message-State: AOJu0Yys1ruRKrDzmfuycfsHGzGdDh5JoskrdApG4kIuOZ48Jaqp/iLk e39dddrSswGMFybd92nItPbEaajKflW+70xz0as4mZEmWdZ8dZFFjyVEIQi9MQ== X-Google-Smtp-Source: AGHT+IGZC3R+I2VvA89HYxYSg4Ao+WE/aEJPwMMpjyENZGIwsc8WIExLuTmv5nBr89XIrOEWeKGuAg== X-Received: by 2002:a05:6a20:6f08:b0:1c1:a25c:745e with SMTP id adf61e73a8af0-1cad7f896admr5742758637.17.1724311268106; Thu, 22 Aug 2024 00:21:08 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8470:6a67:8877:ce2c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ad6e8e9sm615901a12.86.2024.08.22.00.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:21:07 -0700 (PDT) From: Chen-Yu Tsai To: Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] regulator: Return actual error in of_regulator_bulk_get_all() Date: Thu, 22 Aug 2024 15:20:45 +0800 Message-ID: <20240822072047.3097740-3-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240822072047.3097740-1-wenst@chromium.org> References: <20240822072047.3097740-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_002109_580126_2BFDF05B X-CRM114-Status: GOOD ( 12.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If regulator_get() in of_regulator_bulk_get_all() returns an error, that error gets overridden and -EINVAL is always passed out. This masks probe deferral requests and likely won't work properly in all cases. Fix this by letting of_regulator_bulk_get_all() return the original error code. Fixes: 27b9ecc7a9ba ("regulator: Add of_regulator_bulk_get_all") Signed-off-by: Chen-Yu Tsai --- drivers/regulator/of_regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 03afc160fc72..86b680adbf01 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -777,7 +777,7 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, name[i] = '\0'; tmp = regulator_get(dev, name); if (IS_ERR(tmp)) { - ret = -EINVAL; + ret = PTR_ERR(tmp); goto error; } (*consumers)[n].consumer = tmp; From patchwork Thu Aug 22 07:20:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13772885 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBE38C531DF for ; Thu, 22 Aug 2024 07:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VmtdE26bYTfUEgEWFh+anX0TX6bAFO2PB6s9GZztsew=; b=kXHq5fOO8OEI1S1lJMcOswUZLX ZNZT/gvxw28jZ6GZm+NlQRJAxWvzvwqNWCOoqcABDpDPH3TFxiflchyFcCeysfHf2PZxf+6HQiB+7 189XsqkUyKzGiH9GVILsJwlXOrAMivtQmpWDqQuAHsmW2VAW9IZQF8yiCrucZT9wP2KpA2MWlY6nq /JUghzGJZvmfOC8giZjfYVGozFbf1/VQmlHCDMNj9O9ATL1BuCtn3m6UtFadtgYbiidffyy7UcZwx YO0vDH+qYKfW3vrHsp3LdBJIEBy6528503skVe39FSpAaPcA4kRPkpKnYNHqj6DDEIfINvTBZM8aL sUhbgYpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh2Gb-0000000BsTd-2Kxc; Thu, 22 Aug 2024 07:29:57 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh287-0000000Bq2P-0LCi for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 07:21:13 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7141285db14so466610b3a.1 for ; Thu, 22 Aug 2024 00:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724311270; x=1724916070; darn=lists.infradead.org; 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=VmtdE26bYTfUEgEWFh+anX0TX6bAFO2PB6s9GZztsew=; b=GLGg/6FhNuZMyKh3E8rmebDcXnc7hf5BaOFW1nu+HEHGA1wBdugFOp20aO24LUfhLR bftOS3N5hiKhh38JdUZM+MxrgAel42AQnwtgNmRHslNkTJIEEC3OjjgnQsz5g8w8KOU2 q7ItBMZPAmT2au4IX1d6wudBw5iRfBLryprLc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724311270; x=1724916070; 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=VmtdE26bYTfUEgEWFh+anX0TX6bAFO2PB6s9GZztsew=; b=mVaFK/OHBB4KhQLdHi9WxSoRul+pf/G3CE8TmTNzOGUWSQAezfGFk3+jMMXlw0Vg9j mtJa6JmEfXn9mt1IGxZl2X2IbVzv6hclkJFSfAQ9qqI9IoB4IJ6eJu56T/gREd2wpZjw yodXa1yazZexIetko0fq7srAEmfqOGhhuYIINk+3EyOb0yD21l/WfF61N9lACF0ug05z n6vHArEXIb4jyzpJsH0qGe32IHVldfkIYD8frjzjjVcVOHeSnn88Tw5UnGlYILpFyrFW lr8GgcHgoIBXGJwoh4/FhINTUO+EuFYxJodJe92Kx0k3lnz6PlgrNlhlzgOeqpfIvMgX hgvQ== X-Forwarded-Encrypted: i=1; AJvYcCXspwClQoo9CW8mWY/DcQjJ1qtuXOsiFpDoLneCf6n9QwI4NPxK7kZks87FNXgmv1LSQwUCwQgDWQ2ddx0H4Uvi@lists.infradead.org X-Gm-Message-State: AOJu0Yx8+oVnCUu940skNq8+v6ssaxjcN60JpYhI7IAomoPy5es3Kxzg Yg2/iwvrwjvx5CXNrrWt1DCAyaIfEIor8NNph/cPq2Fzde/n3g81f2MqVI7tgA== X-Google-Smtp-Source: AGHT+IGMB+dxjMGNVTHtpKof2PSsuFIg3K1prvJcIxcnrkvlZkXjsgC23fdUHqucez9Q1lukNxGFiA== X-Received: by 2002:a05:6a00:10c4:b0:706:29e6:2ed2 with SMTP id d2e1a72fcca58-71436488fd8mr1064777b3a.5.1724311269746; Thu, 22 Aug 2024 00:21:09 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8470:6a67:8877:ce2c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ad6e8e9sm615901a12.86.2024.08.22.00.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:21:09 -0700 (PDT) From: Chen-Yu Tsai To: Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/3] regulator: Fully clean up on error in of_regulator_bulk_get_all() Date: Thu, 22 Aug 2024 15:20:46 +0800 Message-ID: <20240822072047.3097740-4-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240822072047.3097740-1-wenst@chromium.org> References: <20240822072047.3097740-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_002111_451171_AF8904E1 X-CRM114-Status: GOOD ( 18.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently in of_regulator_bulk_get_all(), if any regulator request fails, the error path releases all regulators already requested, but leaves the |struct regulator_bulk_data| memory to the caller to free, and also leaves the regulator consumer pointers dangling. The latter behavior is not documented, and may not be what the caller is expecting. Instead, explicitly clean up everything on error, and make it clear that the result pointer is only update if the whole request succeeds. Signed-off-by: Chen-Yu Tsai --- drivers/regulator/of_regulator.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 86b680adbf01..d557f7b1ec7c 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -747,19 +747,19 @@ static int is_supply_name(const char *name) * This helper function allows drivers to get several regulator * consumers in one operation. If any of the regulators cannot be * acquired then any regulators that were allocated will be freed - * before returning to the caller. + * before returning to the caller, and @consumers will not be + * changed. */ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, struct regulator_bulk_data **consumers) { int num_consumers = 0; struct regulator *tmp; + struct regulator_bulk_data *_consumers = NULL; struct property *prop; int i, n = 0, ret; char name[64]; - *consumers = NULL; - /* * first pass: get numbers of xxx-supply * second pass: fill consumers @@ -769,7 +769,7 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, i = is_supply_name(prop->name); if (i == 0) continue; - if (!*consumers) { + if (!_consumers) { num_consumers++; continue; } else { @@ -780,25 +780,28 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, ret = PTR_ERR(tmp); goto error; } - (*consumers)[n].consumer = tmp; + _consumers[n].consumer = tmp; n++; continue; } } - if (*consumers) + if (_consumers) { + *consumers = _consumers; return num_consumers; + } if (num_consumers == 0) return 0; - *consumers = kmalloc_array(num_consumers, + _consumers = kmalloc_array(num_consumers, sizeof(struct regulator_bulk_data), GFP_KERNEL); - if (!*consumers) + if (!_consumers) return -ENOMEM; goto restart; error: while (--n >= 0) - regulator_put(consumers[n]->consumer); + regulator_put(_consumers[n].consumer); + kfree(_consumers); return ret; } EXPORT_SYMBOL_GPL(of_regulator_bulk_get_all);