All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Daniel Gutson <daniel@eclypsium.com>
Cc: Derek Kiernan <derek.kiernan@xilinx.com>,
	Tudor Ambarus <tudor.ambarus@microchip.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Richard Hughes <hughsient@gmail.com>,
	Alex Bazhaniuk <alex@eclypsium.com>
Subject: Re: [PATCH] Platform lockdown information in SYSFS
Date: Tue, 4 Aug 2020 16:44:14 +0200	[thread overview]
Message-ID: <20200804144414.GA50022@kroah.com> (raw)
In-Reply-To: <CAFmMkTFEWrMsigabvE2HtmpFXMe0qb8QZJHzMzQ=wZXE1G3fbQ@mail.gmail.com>

On Tue, Aug 04, 2020 at 11:37:02AM -0300, Daniel Gutson wrote:
> On Tue, Aug 4, 2020 at 11:23 AM Greg Kroah-Hartman <
> gregkh@linuxfoundation.org> wrote:
> >
> > On Tue, Aug 04, 2020 at 10:50:13AM -0300, Daniel Gutson wrote:
> > > On Tue, Aug 4, 2020 at 3:41 AM Greg Kroah-Hartman
> > > <gregkh@linuxfoundation.org> wrote:
> > > >
> > > > On Mon, Aug 03, 2020 at 07:04:56PM -0300, Daniel Gutson wrote:
> > > > > > > > Think of this as an input device.  You don't put the random
> input
> > > > > > > > attributes all in one place, you create a new device that
> represents the
> > > > > > > > input interface and register that.
> > > > >
> > > > > I'm having trouble with this. What's the dev_t for the child
> devices?
> > > > > I'm doing
> > > > >     child_device = device_create(&my_class, &pdev->dev, MKDEV(0, 0),
> > > > > NULL, "child");
> > > > > pdev is the pci_device (intel-spi-pci)
> > > > > dmesg shows
> > > > >
> > > > >     sysfs: cannot create duplicate filename '/class/my-class'
> > > > >     (call trace)
> > > > >     kobject_add_internal failed for my-class with -EEXIST, don't try
> > > > > to register things with the same name in the same directory.
> > > >
> > > > Without seeing all of your code, I can't tell you what you are doing
> > > > wrong, but the kernel should be giving you a huge hint here...
> > > >
> > > > Don't create duplicate names in the same subdirectory.
> > >
> > > I'm not doing that. One of my questions is if MKDEV(0, 0) is valid for
> > > create_device, which I inferred so from the documentation.
> >
> > Yes it is, but that's not the error given to you :)
> >
> > Many in-kernel users call device_create() with MKDEV(0, 0)
> >
> > > Here is the listing
> >
> > <snip>
> >
> > It's not in any format to read, please never strip leading whitespace,
> > it hurts my brain...
> 
> (trying again)
> Also, this is in pastebin:  https://pastebin.com/8Ye9eUm5
> 
> #include <linux/kobject.h>
> #include <linux/sysfs.h>
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/list.h>
> #include <linux/slab.h>
> #include <linux/device.h>
> #include <linux/pci.h>
> 
> static ssize_t howareyou_show(struct class *class, struct class_attribute
> *attr,
>    char *buf)
> {
>         return sprintf(buf, "%s\n", "How are you?");
> }
> static CLASS_ATTR_RO(howareyou);

These are rare, as they are "global" for a class, are you sure you want
that?

> 
> static struct class my_class = {
>         .name =         "my-class",
>         .owner =        THIS_MODULE,
> };
> 
> struct device* child_device;
> 
> static int mypci_probe(struct pci_dev *pdev,
>       const struct pci_device_id *id)
> {
>         int ret;
> 
>         ret = pcim_enable_device(pdev);
>         if (ret)
>                 return ret;
> 
>         ret = class_register(&my_class);
>         if (ret < 0)
>                 return ret;
> 
> 
>         pr_info("DFG: Recognized. DID: %lx\n", (unsigned long
> int)id->driver_data);
>         pr_info("DFG: device DID: %lx\n", (unsigned long int)pdev->device);
> 
>         ret = class_create_file(&my_class, &class_attr_howareyou);
>         if (ret != 0) {
>                pr_err("DFG class create file error: %d\n", ret);
>                class_unregister(&my_class);
>                return ret;
>        }
> 
>        child_device = device_create(&my_class, &pdev->dev, MKDEV(0, 0),
> NULL, "child");
>         if (child_device == NULL) {
>                pr_err("DFG error child device NULL");
>         }
> 
>         return ret;
> }
> 


Looks sane, what does your kernel log say when you load this?

thanks,

greg k-h

  parent reply	other threads:[~2020-08-04 14:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30 21:41 [PATCH] Platform lockdown information in SYSFS Daniel Gutson
2020-07-30 22:33 ` Randy Dunlap
2020-07-30 22:40   ` Daniel Gutson
2020-07-31  7:00 ` Greg Kroah-Hartman
2020-07-31 13:30   ` Daniel Gutson
2020-07-31 14:15     ` Greg Kroah-Hartman
2020-08-03 22:04       ` Daniel Gutson
2020-08-04  6:41         ` Greg Kroah-Hartman
2020-08-04 13:50           ` Daniel Gutson
2020-08-04 14:22             ` Greg Kroah-Hartman
     [not found]               ` <CAFmMkTFEWrMsigabvE2HtmpFXMe0qb8QZJHzMzQ=wZXE1G3fbQ@mail.gmail.com>
2020-08-04 14:44                 ` Greg Kroah-Hartman [this message]
2020-08-04 15:05                   ` Daniel Gutson
2020-08-04 15:51                     ` Greg Kroah-Hartman
2020-08-04 16:42                 ` Greg Kroah-Hartman
2020-08-04 17:37                   ` Daniel Gutson

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=20200804144414.GA50022@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=alex@eclypsium.com \
    --cc=arnd@arndb.de \
    --cc=daniel@eclypsium.com \
    --cc=derek.kiernan@xilinx.com \
    --cc=hughsient@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab+huawei@kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=tudor.ambarus@microchip.com \
    --cc=vigneshr@ti.com \
    /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.