All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Schmidt <mschmidt@redhat.com>
To: Rodolfo Giometti <giometti@enneenne.com>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
	"Dr. David Alan Gilbert" <linux@treblig.org>,
	"Ma Ke" <make24@iscas.ac.cn>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"George Spelvin" <linux@horizon.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 6/6] pps: use cdev_device_add()
Date: Mon,  2 Dec 2024 17:34:51 +0100	[thread overview]
Message-ID: <20241202163451.1442566-7-mschmidt@redhat.com> (raw)
In-Reply-To: <20241202163451.1442566-1-mschmidt@redhat.com>

The cdev_set_parent() + cdev_add() + device_add() sequence is just
open-coded cdev_device_add(). Use it.

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
---
 drivers/pps/pps.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 64a8b34aa4ce..89b502855e7b 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -361,13 +361,10 @@ int pps_register_cdev(struct pps_device *pps)
 		goto put_dev;
 	cdev_init(&pps->cdev, &pps_cdev_fops);
 	pps->cdev.owner = pps->info.owner;
-	cdev_set_parent(&pps->cdev, &pps->dev.kobj);
-	err = cdev_add(&pps->cdev, devt, 1);
+
+	err = cdev_device_add(&pps->cdev, &pps->dev);
 	if (err)
 		goto put_dev;
-	err = device_add(&pps->dev);
-	if (err)
-		goto del_cdev;
 
 	/* Override the release function with our own */
 	pps->dev.release = pps_device_destruct;
@@ -377,8 +374,6 @@ int pps_register_cdev(struct pps_device *pps)
 
 	return 0;
 
-del_cdev:
-	cdev_del(&pps->cdev);
 put_dev:
 	put_device(&pps->dev);
 	scoped_guard(mutex, &pps_idr_lock)
@@ -392,8 +387,7 @@ void pps_unregister_cdev(struct pps_device *pps)
 {
 	pr_debug("unregistering pps%d\n", pps->id);
 	pps->lookup_cookie = NULL;
-	device_del(&pps->dev);
-	cdev_del(&pps->cdev);
+	cdev_device_del(&pps->cdev, &pps->dev);
 	put_device(&pps->dev);
 }
 
-- 
2.47.0


  parent reply	other threads:[~2024-12-02 16:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-02 16:34 [PATCH 0/6] pps: fix a UAF and clean up code Michal Schmidt
2024-12-02 16:34 ` [PATCH 1/6] pps: fix cdev use-after-free Michal Schmidt
2024-12-02 16:34 ` [PATCH 2/6] pps: simplify pps_idr_lock locking Michal Schmidt
2024-12-02 16:34 ` [PATCH 3/6] pps: use scoped_guard for pps_idr_lock Michal Schmidt
2024-12-03  9:06   ` Uwe Kleine-König
2024-12-02 16:34 ` [PATCH 4/6] pps: print error in both cdev and dev error paths in pps_register_cdev() Michal Schmidt
2024-12-02 16:34 ` [PATCH 5/6] pps: embed "dev" in the pps_device Michal Schmidt
2024-12-03  1:02   ` kernel test robot
2024-12-03  2:04   ` kernel test robot
2024-12-02 16:34 ` Michal Schmidt [this message]
2024-12-02 16:56 ` [PATCH 0/6] pps: fix a UAF and clean up code Calvin Owens
2024-12-02 17:58   ` Michal Schmidt

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=20241202163451.1442566-7-mschmidt@redhat.com \
    --to=mschmidt@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=giometti@enneenne.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@horizon.com \
    --cc=linux@treblig.org \
    --cc=make24@iscas.ac.cn \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.