public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shahar Avidar <ikobh7@gmail.com>
To: gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl,
	andriy.shevchenko@linux.intel.com, robh@kernel.org,
	felixkimbu1@gmail.com, dan.carpenter@linaro.org,
	krzysztof.kozlowski@linaro.org
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] staging: pi433: Use class_create instead of class_register.
Date: Wed,  1 May 2024 08:58:19 +0300	[thread overview]
Message-ID: <20240501055820.603272-2-ikobh7@gmail.com> (raw)
In-Reply-To: <20240501055820.603272-1-ikobh7@gmail.com>

Make use of a higher level API.
Reduce global memory allocation from struct class to pointer size.

Signed-off-by: Shahar Avidar <ikobh7@gmail.com>
---
 drivers/staging/pi433/pi433_if.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index 31aeabb1f153..c8c1d296184b 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -59,9 +59,7 @@ static DEFINE_MUTEX(minor_lock); /* Protect idr accesses */
 static struct dentry *root_dir;	/* debugfs root directory for the driver */
 
 /* mainly for udev to create /dev/pi433 */
-static const struct class pi433_class = {
-	.name = "pi433",
-};
+static const struct class *pi433_class;
 
 /*
  * tx config is instance specific
@@ -1263,7 +1261,7 @@ static int pi433_probe(struct spi_device *spi)
 
 	/* create device */
 	pi433->devt = MKDEV(MAJOR(pi433_devt), pi433->minor);
-	pi433->dev = device_create(&pi433_class,
+	pi433->dev = device_create(pi433_class,
 				   &spi->dev,
 				   pi433->devt,
 				   pi433,
@@ -1319,7 +1317,7 @@ static int pi433_probe(struct spi_device *spi)
 cdev_failed:
 	kthread_stop(pi433->tx_task_struct);
 send_thread_failed:
-	device_destroy(&pi433_class, pi433->devt);
+	device_destroy(pi433_class, pi433->devt);
 device_create_failed:
 	pi433_free_minor(pi433);
 minor_failed:
@@ -1346,7 +1344,7 @@ static void pi433_remove(struct spi_device *spi)
 
 	kthread_stop(pi433->tx_task_struct);
 
-	device_destroy(&pi433_class, pi433->devt);
+	device_destroy(pi433_class, pi433->devt);
 
 	cdev_del(pi433->cdev);
 
@@ -1401,9 +1399,11 @@ static int __init pi433_init(void)
 	if (status < 0)
 		return status;
 
-	status = class_register(&pi433_class);
-	if (status)
+	pi433_class = class_create("pi433");
+	if (IS_ERR(pi433_class)) {
+		status = PTR_ERR(pi433_class);
 		goto unreg_chrdev;
+	}
 
 	root_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
 
@@ -1415,7 +1415,7 @@ static int __init pi433_init(void)
 
 unreg_class_and_remove_dbfs:
 	debugfs_remove(root_dir);
-	class_unregister(&pi433_class);
+	class_destroy(pi433_class);
 unreg_chrdev:
 	unregister_chrdev(MAJOR(pi433_devt), pi433_spi_driver.driver.name);
 	return status;
@@ -1427,7 +1427,7 @@ static void __exit pi433_exit(void)
 {
 	spi_unregister_driver(&pi433_spi_driver);
 	debugfs_remove(root_dir);
-	class_unregister(&pi433_class);
+	class_destroy(pi433_class);
 	unregister_chrdev(MAJOR(pi433_devt), pi433_spi_driver.driver.name);
 }
 module_exit(pi433_exit);

base-commit: 75ff53c44f5e151d21d949416633b56e56160124
prerequisite-patch-id: 91943193af2fea74182be67fb583235a3fbeb77b
prerequisite-patch-id: 2cad031ba6a0782a67ab1645ff034a8be65c2e76
prerequisite-patch-id: 1a852ed8f9d133aec7c651fd9007e59e39c55fb7
-- 
2.34.1


  reply	other threads:[~2024-05-01  5:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01  5:58 [PATCH 0/2] staging: pi433: Use class_create API Shahar Avidar
2024-05-01  5:58 ` Shahar Avidar [this message]
2024-05-01 14:00   ` [PATCH 1/2] staging: pi433: Use class_create instead of class_register Dan Carpenter
2024-05-01 14:14     ` Greg KH
2024-05-02  8:51       ` Shahar Avidar
2024-05-01 14:12   ` Greg KH
2024-05-02  8:40     ` Shahar Avidar
2024-05-02  8:54       ` Greg KH
2024-05-01  5:58 ` [PATCH 2/2] staging: pi433: Rename goto label Shahar Avidar
2024-05-01 14:06   ` Dan Carpenter
2024-05-02  8:44     ` Shahar Avidar
2024-05-02  8:59       ` Dan Carpenter

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=20240501055820.603272-2-ikobh7@gmail.com \
    --to=ikobh7@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=felixkimbu1@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=robh@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