Skip to content

Commit 6149f83

Browse files
committed
device.h: move kobj_to_dev() to use container_of_const()
Instead of rolling our own const-checking logic, use the newly introduced container_of_const() to handle it all for us automatically. Cc: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Link: https://lore.kernel.org/r/20221205121206.166576-2-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 64f6a5d commit 6149f83

1 file changed

Lines changed: 1 addition & 20 deletions

File tree

include/linux/device.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -680,26 +680,7 @@ struct device_link {
680680
bool supplier_preactivated; /* Owned by consumer probe. */
681681
};
682682

683-
static inline struct device *__kobj_to_dev(struct kobject *kobj)
684-
{
685-
return container_of(kobj, struct device, kobj);
686-
}
687-
688-
static inline const struct device *__kobj_to_dev_const(const struct kobject *kobj)
689-
{
690-
return container_of(kobj, const struct device, kobj);
691-
}
692-
693-
/*
694-
* container_of() will happily take a const * and spit back a non-const * as it
695-
* is just doing pointer math. But we want to be a bit more careful in the
696-
* driver code, so manually force any const * of a kobject to also be a const *
697-
* to a device.
698-
*/
699-
#define kobj_to_dev(kobj) \
700-
_Generic((kobj), \
701-
const struct kobject *: __kobj_to_dev_const, \
702-
struct kobject *: __kobj_to_dev)(kobj)
683+
#define kobj_to_dev(__kobj) container_of_const(__kobj, struct device, kobj)
703684

704685
/**
705686
* device_iommu_mapped - Returns true when the device DMA is translated

0 commit comments

Comments
 (0)