public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: Lee Jones <lee@kernel.org>
Subject: [PATCH v1 3/6] mfd: kempld: Simplify device registration
Date: Fri, 23 Feb 2024 21:49:52 +0200	[thread overview]
Message-ID: <20240223195113.880121-4-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20240223195113.880121-1-andriy.shevchenko@linux.intel.com>

Use platform_device_register_full() instead of open coding this
function.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/mfd/kempld-core.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/drivers/mfd/kempld-core.c b/drivers/mfd/kempld-core.c
index e8ac30528085..e207a62d6577 100644
--- a/drivers/mfd/kempld-core.c
+++ b/drivers/mfd/kempld-core.c
@@ -6,6 +6,7 @@
  * Author: Michael Brunner <michael.brunner@kontron.com>
  */
 
+#include <linux/err.h>
 #include <linux/platform_device.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/kempld.h>
@@ -131,28 +132,20 @@ static struct platform_device *kempld_pdev;
 static int kempld_create_platform_device(const struct dmi_system_id *id)
 {
 	const struct kempld_platform_data *pdata = id->driver_data;
-	int ret;
+	const struct platform_device_info pdevinfo = {
+		.name = "kempld",
+		.id = PLATFORM_DEVID_NONE,
+		.res = pdata->ioresource,
+		.num_res = 1,
+		.data = pdata,
+		.size_data = sizeof(*pdata),
+	};
 
-	kempld_pdev = platform_device_alloc("kempld", -1);
-	if (!kempld_pdev)
-		return -ENOMEM;
-
-	ret = platform_device_add_data(kempld_pdev, pdata, sizeof(*pdata));
-	if (ret)
-		goto err;
-
-	ret = platform_device_add_resources(kempld_pdev, pdata->ioresource, 1);
-	if (ret)
-		goto err;
-
-	ret = platform_device_add(kempld_pdev);
-	if (ret)
-		goto err;
+	kempld_pdev = platform_device_register_full(&pdevinfo);
+	if (IS_ERR(kempld_pdev))
+		return PTR_ERR(kempld_pdev);
 
 	return 0;
-err:
-	platform_device_put(kempld_pdev);
-	return ret;
 }
 
 /**
@@ -424,7 +417,7 @@ static int kempld_probe(struct platform_device *pdev)
 	struct resource *ioport;
 	int ret;
 
-	if (kempld_pdev == NULL) {
+	if (IS_ERR_OR_NULL(kempld_pdev)) {
 		/*
 		 * No kempld_pdev device has been registered in kempld_init,
 		 * so we seem to be probing an ACPI platform device.
-- 
2.43.0.rc1.1.gbec44491f096


  parent reply	other threads:[~2024-02-23 19:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-23 19:49 [PATCH v1 0/6] mfd: kempld: A few cleanups Andy Shevchenko
2024-02-23 19:49 ` [PATCH v1 1/6] mfd: kempld: Replace ACPI code with agnostic one Andy Shevchenko
2024-02-23 19:49 ` [PATCH v1 2/6] mfd: kempld: Use device core to create driver-specific device attributes Andy Shevchenko
2024-02-23 19:49 ` Andy Shevchenko [this message]
2024-02-23 19:49 ` [PATCH v1 4/6] mfd: kempld: Use PLATFORM_DEVID_NONE instead of -1 Andy Shevchenko
2024-02-23 19:49 ` [PATCH v1 5/6] mfd: kempld: Drop duplicate NULL check in ->exit() Andy Shevchenko
2024-02-23 19:49 ` [PATCH v1 6/6] mfd: kempld: Remove dead code Andy Shevchenko
2024-04-02 15:31 ` [PATCH v1 0/6] mfd: kempld: A few cleanups Andy Shevchenko
2024-04-11  9:29   ` Lee Jones
2024-04-11 10:20     ` Andy Shevchenko
2024-04-11 10:56       ` Lee Jones
2024-04-11 12:12         ` Andy Shevchenko
2024-04-11 10:10 ` Lee Jones

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=20240223195113.880121-4-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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