Kernel Newbies archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Richard <richard_siegfried@systemli.org>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: ktypes vs. devices classes (struct class)
Date: Mon, 2 Oct 2023 11:00:35 +0200	[thread overview]
Message-ID: <2023100250-dental-reproduce-36f4@gregkh> (raw)
In-Reply-To: <732c70a0-a6a1-8dc7-d4d1-c817154e050c@systemli.org>

On Sun, Oct 01, 2023 at 11:15:12PM +0200, Richard wrote:
> > > I've seen struct class defines **class_groups, but (contrary to struct
> > > kobj_type) not the corresponding struct sysfs_ops, why? Where is it then?
> > 
> > groups are used to define attributes (i.e. sysfs files).  sysfs_ops is
> > much "lower" in the stack.
> > 
> > I think the description of how the driver model works in the book, Linux
> > Device Drivers, 3rd edition, free online, should still represent how
> > things work on this layer pretty well, although we have changed things
> > in places over time since the book was written.  Try looking that first.
> 
> I looked it up and my understanding is that those attributes are actually
> all embedded in instances of "struct class_attribute" and since they all
> bring their own store() and show() functions it's not necesarry to contain
> them in directly in "struct class". The whole mechanic with container_of()
> makes sure in the end the right "subroutine" gets called.
> 
> Is this correct?

Close enough, yes :)

The "fun" with attributes and sysfs files is a very tricky one, relying
entirely on the location of the callbacks in memory to match up properly
with some other structures and to pass around pointers like crazy.  It
has played havoc on some tools like CFI and will be very "interesting"
to see how it every works in languages other than C (i.e. rust.)

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      reply	other threads:[~2023-10-02  9:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30  0:12 ktypes vs. devices classes (struct class) Richard
2023-09-30  6:30 ` Greg KH
2023-09-30 18:17   ` Richard
2023-10-01  9:50     ` Greg KH
2023-10-01 10:28       ` Greg KH
2023-10-01 21:22         ` Richard
2023-10-01 21:15       ` Richard
2023-10-02  9:00         ` Greg KH [this message]

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=2023100250-dental-reproduce-36f4@gregkh \
    --to=greg@kroah.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=richard_siegfried@systemli.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).