From: Greg KH <greg@kroah.com>
To: linux-parport@lists.infradead.org, philb@gnu.org,
tim@cyberelk.net, andrea@suse.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] register sysfs device for lp devices
Date: Fri, 17 Feb 2006 17:45:41 -0800 [thread overview]
Message-ID: <20060218014541.GA17364@kroah.com> (raw)
In-Reply-To: <20060217113836.GA26254@pcpool00.mathematik.uni-freiburg.de>
On Fri, Feb 17, 2006 at 12:38:36PM +0100, Bernhard R. Link wrote:
> Give class_device_create a device pointer parport drivers
> can set via a new parport_set_dev.
> Also patch parport_gsci and parport_pc as example.
>
> Signed-of-by: Bernhard R Link <brlink@debian.org>
>
> ---
>
> Compile and run-tested with linux-2.6.16-rc3-git4.
>
> Index: mlinux-2.6.15-git12/drivers/char/lp.c
> ===================================================================
> --- mlinux-2.6.15-git12.orig/drivers/char/lp.c 2006-02-10 08:22:48.000000000 +0100
> +++ mlinux-2.6.15-git12/drivers/char/lp.c 2006-02-13 14:46:29.000000000 +0100
> @@ -805,7 +805,7 @@
> if (reset)
> lp_reset(nr);
>
> - class_device_create(lp_class, NULL, MKDEV(LP_MAJOR, nr), NULL,
> + class_device_create(lp_class, NULL, MKDEV(LP_MAJOR, nr), port->dev,
> "lp%d", nr);
> devfs_mk_cdev(MKDEV(LP_MAJOR, nr), S_IFCHR | S_IRUGO | S_IWUGO,
> "printers/%d", nr);
> Index: mlinux-2.6.15-git12/drivers/parport/parport_gsc.c
> ===================================================================
> --- mlinux-2.6.15-git12.orig/drivers/parport/parport_gsc.c 2006-02-13 14:27:53.000000000 +0100
> +++ mlinux-2.6.15-git12/drivers/parport/parport_gsc.c 2006-02-13 14:46:29.000000000 +0100
> @@ -340,6 +340,9 @@
> parport_gsc_write_data(p, 0);
> parport_gsc_data_forward (p);
>
> + /* Tell sysfs which device is behind this parport */
> + parport_set_dev (p, &dev->dev);
> +
> /* Now that we've told the sharing engine about the port, and
> found out its characteristics, let the high-level drivers
> know about it. */
> Index: mlinux-2.6.15-git12/drivers/parport/parport_pc.c
> ===================================================================
> --- mlinux-2.6.15-git12.orig/drivers/parport/parport_pc.c 2006-02-13 14:30:26.000000000 +0100
> +++ mlinux-2.6.15-git12/drivers/parport/parport_pc.c 2006-02-13 14:46:29.000000000 +0100
> @@ -2340,6 +2340,7 @@
> spin_lock(&ports_lock);
> list_add(&priv->list, &ports_list);
> spin_unlock(&ports_lock);
> + parport_set_dev (p, &dev->dev);
> parport_announce_port (p);
>
> return p;
> Index: mlinux-2.6.15-git12/drivers/parport/share.c
> ===================================================================
> --- mlinux-2.6.15-git12.orig/drivers/parport/share.c 2006-02-13 14:30:26.000000000 +0100
> +++ mlinux-2.6.15-git12/drivers/parport/share.c 2006-02-13 14:46:29.000000000 +0100
> @@ -341,6 +341,11 @@
>
> tmp->waithead = tmp->waittail = NULL;
>
> + /*
> + * no sysfs device known unless the announcer sets it before
> + */
> + tmp->dev = NULL;
> +
This is not needed, as tmp is zeroed out earlier in the function.
> return tmp;
> }
>
> Index: mlinux-2.6.15-git12/include/linux/parport.h
> ===================================================================
> --- mlinux-2.6.15-git12.orig/include/linux/parport.h 2006-02-13 14:30:42.000000000 +0100
> +++ mlinux-2.6.15-git12/include/linux/parport.h 2006-02-13 14:46:29.000000000 +0100
> @@ -258,6 +258,7 @@
> struct semaphore irq;
> };
>
> +struct device;
> /* A parallel port */
> struct parport {
> unsigned long base; /* base address */
> @@ -313,6 +314,8 @@
>
> struct list_head full_list;
> struct parport *slaves[3];
> +
> + struct device *dev; /* for the sysfs device symlink */
> };
>
> #define DEFAULT_SPIN_TIME 500 /* us */
> @@ -331,6 +334,10 @@
> struct parport *parport_register_port(unsigned long base, int irq, int dma,
> struct parport_operations *ops);
>
> +/* parport_set_dev set the generic device behind this port, so drivers
> + * can display it in their sysfs nodes */
> +#define parport_set_dev(port,devptr) ((port)->dev = (devptr))
If you are going to save off a pointer to a structure, you need to
increment it's reference count. You aren't doing that here, and bad
things might happen if it gets removed from under you :(
thanks,
greg k-h
next prev parent reply other threads:[~2006-02-18 1:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-17 11:38 [PATCH] register sysfs device for lp devices Bernhard R. Link
2006-02-17 17:43 ` Stephen Hemminger
2006-02-18 12:05 ` Bernhard R. Link
2006-02-18 1:45 ` Greg KH [this message]
2006-02-18 13:00 ` Bernhard R. Link
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=20060218014541.GA17364@kroah.com \
--to=greg@kroah.com \
--cc=andrea@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-parport@lists.infradead.org \
--cc=philb@gnu.org \
--cc=tim@cyberelk.net \
/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