Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1580067

Re: [PATCH] device-dax: don't set kobj parent during cdev init

From Dan Williams <dan.j.williams@intel.com>
Newsgroups linux.kernel
Subject Re: [PATCH] device-dax: don't set kobj parent during cdev init
Date 2017-02-13 21:50 +0100
Message-ID <tavJn-dK-5@gated-at.bofh.it> (permalink)
References (7 earlier) <t9KAO-441-15@gated-at.bofh.it> <t9KU9-4aS-9@gated-at.bofh.it> <t9L3Q-4eF-21@gated-at.bofh.it> <t9L3Q-4eF-19@gated-at.bofh.it> <t9VcS-2g7-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, Feb 11, 2017 at 9:42 PM, Logan Gunthorpe <logang@deltatee.com> wrote:
> On 11/02/17 11:58 AM, Dan Williams wrote:
>> Also when using an embedded cdev how would you recommend avoiding this problem?
>
> I don't know. Hopefully, Greg has a good idea. But it sounds like a
> general problem that a lot of cdev's actually suffer from without
> realizing. Perhaps we need a more general solution. Some way for the
> cdev to reference its containing structure in a way that it's designed
> for such that anyone writing a driver will do the right thing without
> needing to dive into the kobjects.
>

How about something like the below? I.e. hide the details with a new
helper api so that all driver writers need to worry about is the
parent device and cdev_del(). This is similar to the device_add_disk()
and del_gendisk() pairing that we have for block-device drivers.

diff --git a/fs/char_dev.c b/fs/char_dev.c
index 3bc97002c86f..4c5d51cdd353 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -471,6 +471,12 @@ int cdev_add(struct cdev *p, dev_t dev, unsigned count)
        return 0;
 }

+int device_add_cdev(struct device *dev, struct cdev *p)
+{
+       p->kobj.parent = &dev->kobj;
+       return cdev_add(p, dev->devt, 1);
+}
+
 static void cdev_unmap(dev_t dev, unsigned count)
 {
        kobj_unmap(cdev_map, dev, count);
diff --git a/include/linux/cdev.h b/include/linux/cdev.h
index f8763615a5f2..043168df1d8f 100644
--- a/include/linux/cdev.h
+++ b/include/linux/cdev.h
@@ -25,6 +25,7 @@ struct cdev *cdev_alloc(void);
 void cdev_put(struct cdev *p);

 int cdev_add(struct cdev *, dev_t, unsigned);
+int device_add_cdev(struct device *dev, struct cdev *);

 void cdev_del(struct cdev *);

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] device-dax: don't set kobj parent during cdev init Logan Gunthorpe <logang@deltatee.com> - 2017-02-10 20:20 +0100
  Re: [PATCH] device-dax: don't set kobj parent during cdev init Logan Gunthorpe <logang@deltatee.com> - 2017-02-10 20:30 +0100
  Re: [PATCH] device-dax: don't set kobj parent during cdev init Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-10 20:50 +0100
  Re: [PATCH] device-dax: don't set kobj parent during cdev init Dan Williams <dan.j.williams@intel.com> - 2017-02-10 20:50 +0100
    Re: [PATCH] device-dax: don't set kobj parent during cdev init Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-10 21:20 +0100
      Re: [PATCH] device-dax: don't set kobj parent during cdev init Dan Williams <dan.j.williams@intel.com> - 2017-02-10 23:30 +0100
        Re: [PATCH] device-dax: don't set kobj parent during cdev init Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-11 08:20 +0100
          Re: [PATCH] device-dax: don't set kobj parent during cdev init Dan Williams <dan.j.williams@intel.com> - 2017-02-11 10:00 +0100
            Re: [PATCH] device-dax: don't set kobj parent during cdev init Logan Gunthorpe <logang@deltatee.com> - 2017-02-11 19:00 +0100
              Re: [PATCH] device-dax: don't set kobj parent during cdev init Dan Williams <dan.j.williams@intel.com> - 2017-02-11 19:30 +0100
                Re: [PATCH] device-dax: don't set kobj parent during cdev init Logan Gunthorpe <logang@deltatee.com> - 2017-02-11 19:50 +0100
                Re: [PATCH] device-dax: don't set kobj parent during cdev init Dan Williams <dan.j.williams@intel.com> - 2017-02-11 20:00 +0100
                Re: [PATCH] device-dax: don't set kobj parent during cdev init Logan Gunthorpe <logang@deltatee.com> - 2017-02-12 06:50 +0100
                Re: [PATCH] device-dax: don't set kobj parent during cdev init Dan Williams <dan.j.williams@intel.com> - 2017-02-13 21:50 +0100
                Re: [PATCH] device-dax: don't set kobj parent during cdev init Logan Gunthorpe <logang@deltatee.com> - 2017-02-13 23:40 +0100
                Re: [PATCH] device-dax: don't set kobj parent during cdev init Dan Williams <dan.j.williams@intel.com> - 2017-02-11 20:00 +0100

csiph-web