lkml.org 
[lkml]   [2022]   [Dec]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/4] device.h: move kobj_to_dev() to use container_of_const()
Date
Instead of rolling our own const-checking logic, use the newly
introduced container_of_const() to handle it all for us automatically.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/device.h | 22 ++--------------------
1 file changed, 2 insertions(+), 20 deletions(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index 84ae52de6746..8ad2cd21b335 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -680,26 +680,8 @@ struct device_link {
bool supplier_preactivated; /* Owned by consumer probe. */
};

-static inline struct device *__kobj_to_dev(struct kobject *kobj)
-{
- return container_of(kobj, struct device, kobj);
-}
-
-static inline const struct device *__kobj_to_dev_const(const struct kobject *kobj)
-{
- return container_of(kobj, const struct device, kobj);
-}
-
-/*
- * container_of() will happily take a const * and spit back a non-const * as it
- * is just doing pointer math. But we want to be a bit more careful in the
- * driver code, so manually force any const * of a kobject to also be a const *
- * to a device.
- */
-#define kobj_to_dev(kobj) \
- _Generic((kobj), \
- const struct kobject *: __kobj_to_dev_const, \
- struct kobject *: __kobj_to_dev)(kobj)
+#define kobj_to_dev(__kobj) \
+ container_of_const(struct kobject, __kobj, struct device, kobj)

/**
* device_iommu_mapped - Returns true when the device DMA is translated
--
2.38.1
\
 
 \ /
  Last update: 2022-12-01 20:32    [W:0.100 / U:1.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site