Re: [PATCH v2 14/18] sysfs: Allow symlinks to be added between sibling groups

Greg Kroah-Hartman
2024-07-04T10:14:13Z

On Sun, Jun 30, 2024 at 09:49:00PM +0200, Lukas Wunner wrote:
> A subsequent commit has the need to create a symlink from an attribute
> in a first group to an attribute in a second group. Both groups belong
> to the same kobject.
>
> More specifically, each signature received from an authentication-
> capable device is going to be represented by a file in the first group
> and shall be accompanied by a symlink pointing to the certificate slot
> in the second group which was used to generate the signature (a device
> may have multiple certificate slots and each is represented by a
> separate file in the second group):
>
> /sys/devices/.../signatures/0_certificate_chain -> .../certificates/slot0
>
> There is already a sysfs_add_link_to_group() helper to add a symlink to
> a group which points to another kobject, but this isn't what's needed
> here.
>
> So add a new function to add a symlink among sibling groups of the same
> kobject.
>
> The existing sysfs_add_link_to_group() helper goes through a locking
> dance of acquiring sysfs_symlink_target_lock in order to acquire a
> reference on the target kobject. That's unnecessary for the present
> use case as the link itself and its target reside below the same
> kobject.
>
> To simplify error handling in the newly introduced function, add a
> DEFINE_FREE() clause for kernfs_put().

Nice!

>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>