public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: wim@iguana.be, linux-watchdog@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 4/5] watchdog: create all the proper device files
Date: Tue, 28 Feb 2012 22:48:25 +0000	[thread overview]
Message-ID: <20120228224822.8961.23797.stgit@bob.linux.org.uk> (raw)
In-Reply-To: <20120228224710.8961.46003.stgit@bob.linux.org.uk>

From: Alan Cox <alan@linux.intel.com>

Signed-off-by: Alan Cox <alan@linux.intel.com>
---

 drivers/watchdog/watchdog_dev.c |   29 ++++++++++++++++++++++++-----
 include/linux/watchdog.h        |    5 ++++-
 2 files changed, 28 insertions(+), 6 deletions(-)


diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 253e082..7edab6d 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -42,6 +42,8 @@
 #include <linux/init.h>		/* For __init/__exit/... */
 #include <linux/uaccess.h>	/* For copy_to_user/put_user/... */
 
+static struct class *watchdog_class;	/* So we have someone to create
+					   our devices */
 static dev_t dog_devt;		/* Watchdog device range */
 static unsigned long dog_mask;	/* Watcodgs that are in use */
 /* the watchdog device behind /dev/watchdog */
@@ -434,13 +436,21 @@ static int watchdog_add_device(struct watchdog_device *watchdog)
 	watchdog->devt = MKDEV(MAJOR(dog_devt), watchdog->id);
 	watchdog->cdev.owner = watchdog->ops->owner;
 	cdev_init(&watchdog->cdev, &watchdog_multi_fops);
-
 	/* Add the device */
 	err  = cdev_add(&watchdog->cdev, watchdog->devt, 1);
-	if (err)
+	if (err) {
 		pr_err("watchdog%d unable to add device %d:%d\n",
 			watchdog->id,  MAJOR(dog_devt), watchdog->id);
-	return err;
+		return err;
+	}
+	watchdog->dev = device_create(watchdog_class, watchdog->busdev,
+					MKDEV(MAJOR(dog_devt), watchdog->id),
+					NULL, "watchdog%d", watchdog->id);
+	if (IS_ERR(watchdog->dev)) {
+		cdev_del(&watchdog->cdev);
+		return PTR_ERR(watchdog->dev);
+	}
+	return 0;
 }
 
 /**
@@ -452,6 +462,7 @@ static int watchdog_add_device(struct watchdog_device *watchdog)
 static void watchdog_del_device(struct watchdog_device *watchdog)
 {
 	cdev_del(&watchdog->cdev);
+	device_destroy(watchdog_class, MKDEV(MAJOR(dog_devt), watchdog->id));
 }	
 
 /**
@@ -518,9 +529,16 @@ int watchdog_dev_unregister(struct watchdog_device *watchdog)
 int __init watchdog_init(void)
 {
 	int err = alloc_chrdev_region(&dog_devt, 0, DOG_MAX, "watchdog");
-	if (err < 0)
+	if (err < 0) {
 		pr_err("watchdog: unable to allocate char dev region\n");
-	return err;
+		return err;
+	}
+	watchdog_class = class_create(THIS_MODULE, "watchdog");
+	if (IS_ERR(watchdog_class)) {
+		unregister_chrdev_region(dog_devt, DOG_MAX);
+		return PTR_ERR(watchdog_class);
+	}
+	return 0;
 }
 
 /**
@@ -531,6 +549,7 @@ int __init watchdog_init(void)
 void __exit watchdog_exit(void)
 {
 	unregister_chrdev_region(dog_devt, DOG_MAX);
+	class_destroy(watchdog_class);
 }
 
 module_init(watchdog_init);
diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h
index c80e1ae..598c407 100644
--- a/include/linux/watchdog.h
+++ b/include/linux/watchdog.h
@@ -108,7 +108,10 @@ struct watchdog_ops {
  */
 struct watchdog_device {
 	struct cdev cdev;		/* Character device */
-	dev_t devt;			/* Our device */
+	struct device *dev;		/* Device for our node */
+	struct device *busdev;		/* Parent bus device (set by caller
+							if used) */
+	dev_t devt;			/* Our device devt */
 	int id;				/* Watchdog id */
 
 	const struct watchdog_info *info;


  parent reply	other threads:[~2012-02-28 22:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28 22:47 [PATCH 1/5] watchdog: Add multiple device support Alan Cox
2012-02-28 22:47 ` [PATCH 2/5] watchdog: Add a flag to indicate the watchdog doesn't reboot things Alan Cox
2012-02-28 22:48 ` [PATCH 3/5] softdog: convert to watchdog core Alan Cox
2012-02-28 22:48 ` Alan Cox [this message]
2012-02-28 22:48 ` [PATCH 5/5] watchdog: use dev_ functions Alan Cox

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=20120228224822.8961.23797.stgit@bob.linux.org.uk \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=wim@iguana.be \
    /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