public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Fei Shao <fshao@chromium.org>,
	linux-kernel@vger.kernel.org, patches@lists.linux.dev
Subject: [PATCH 7/8] spmi: Return meaningful errors in spmi_controller_alloc()
Date: Wed,  6 Dec 2023 15:17:30 -0800	[thread overview]
Message-ID: <20231206231733.4031901-8-sboyd@kernel.org> (raw)
In-Reply-To: <20231206231733.4031901-1-sboyd@kernel.org>

From: Fei Shao <fshao@chromium.org>

spmi_controller_alloc() currently returns NULL to all types of errors,
which can be improved.

Use appropriate error code in returns and pass the errors from used
functions where possible.

Signed-off-by: Fei Shao <fshao@chromium.org>
Link: https://lore.kernel.org/r/20230824104101.4083400-6-fshao@chromium.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
---
 drivers/spmi/spmi-devres.c | 4 ++--
 drivers/spmi/spmi.c        | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/spmi/spmi-devres.c b/drivers/spmi/spmi-devres.c
index 7683e6fdb18f..62c4b3f24d06 100644
--- a/drivers/spmi/spmi-devres.c
+++ b/drivers/spmi/spmi-devres.c
@@ -20,9 +20,9 @@ struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t
 		return ERR_PTR(-ENOMEM);
 
 	ctrl = spmi_controller_alloc(parent, size);
-	if (!ctrl) {
+	if (IS_ERR(ctrl)) {
 		devres_free(ptr);
-		return ERR_PTR(-ENOMEM);
+		return ctrl;
 	}
 
 	*ptr = ctrl;
diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c
index 7313d4c18a04..5f11ced3f8b9 100644
--- a/drivers/spmi/spmi.c
+++ b/drivers/spmi/spmi.c
@@ -445,11 +445,11 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent,
 	int id;
 
 	if (WARN_ON(!parent))
-		return NULL;
+		return ERR_PTR(-EINVAL);
 
 	ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL);
 	if (!ctrl)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	device_initialize(&ctrl->dev);
 	ctrl->dev.type = &spmi_ctrl_type;
@@ -463,7 +463,7 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent,
 		dev_err(parent,
 			"unable to allocate SPMI controller identifier.\n");
 		spmi_controller_put(ctrl);
-		return NULL;
+		return ERR_PTR(id);
 	}
 
 	ctrl->nr = id;
-- 
https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/
https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git


  parent reply	other threads:[~2023-12-06 23:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06 23:17 [PATCH 0/8] SPMI patches for the merge window Stephen Boyd
2023-12-06 23:17 ` [PATCH 1/8] spmi: mtk-pmif: Serialize PMIF status check and command submission Stephen Boyd
2023-12-15 16:12   ` Greg Kroah-Hartman
2023-12-06 23:17 ` [PATCH 2/8] spmi: mediatek: Fix UAF on device remove Stephen Boyd
2023-12-06 23:17 ` [PATCH 3/8] spmi: Introduce device-managed functions Stephen Boyd
2023-12-06 23:17 ` [PATCH 4/8] spmi: Use devm_spmi_controller_alloc() Stephen Boyd
2023-12-06 23:17 ` [PATCH 5/8] spmi: mtk-pmif: Reorder driver remove sequence Stephen Boyd
2023-12-06 23:17 ` [PATCH 6/8] spmi: hisi-spmi-controller: Use devm_spmi_controller_add() Stephen Boyd
2023-12-06 23:17 ` Stephen Boyd [this message]
2023-12-06 23:17 ` [PATCH 8/8] spmi: mediatek: add device id check Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231206231733.4031901-8-sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=fshao@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox