All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard <richard_siegfried@systemli.org>
To: Greg KH <greg@kroah.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: ktypes vs. devices classes (struct class)
Date: Sun, 1 Oct 2023 23:15:12 +0200	[thread overview]
Message-ID: <732c70a0-a6a1-8dc7-d4d1-c817154e050c@systemli.org> (raw)
In-Reply-To: <2023100146-storm-unsmooth-d18c@gregkh>


> 
> Close.
> 
> "struct class" represents how userspace interacts with a device (tty /
> input / block / etc.)
> 
> "struct kobj_type" is needed to describe what "type" of struct kobject a
> specific kobject is.  It defines a number of operations that handle the
> lifespan of the kobject.

Oki

> 
>> My digging however has brought me to a few new questions:
>>
>> Do all devices (their kobjects to be more precise) in one class (e.g.
>> /sys/class/net ) belong to the same ktype?
> 
> ktype is "lower" than classes.  ktype is not used for things in the
> driver model, it's used for things "lower" than the driver model (and to
> implement the driver model itself.)

Ahhh

> 
> So no driver should ever be messing with a ktype.  If you want to have a
> different "type" of device on the same bus or class, use "struct
> device_type" as that's what that is for.
> 
>> Is it possible that one device belongs to several classes?
> 
> No.
> 
>> 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?

> 
>>> When we implemented them, we didn't think so but maybe something has
>>> changed to now allow this?  If so, great, please send us patches to do
>>> so!
>>
>> Oh please don't misunderstand me, even if we had come to an agreement that
>> this architecture was unelegent (which it isn't I see the point now), I
>> don't think that would have been reason enough to change it.
> 
> Change is good if it is needed, that's how code evolves, based on new
> ideas and use cases.  So that's fine if needed.
> 
> hope this helps,

It does, thank you

-- Richard
> 
> greg k-h

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

  parent reply	other threads:[~2023-10-01 21:16 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 [this message]
2023-10-02  9:00         ` Greg KH

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=732c70a0-a6a1-8dc7-d4d1-c817154e050c@systemli.org \
    --to=richard_siegfried@systemli.org \
    --cc=greg@kroah.com \
    --cc=kernelnewbies@kernelnewbies.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 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.