[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0iFsYFw=aY6cc+0y0M8TApC5YphUr_XpxUP_PBc2tZb1g@mail.gmail.com>
Date: Mon, 5 Dec 2022 15:00:28 +0100
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Jason Gunthorpe <jgg@...dia.com>
Subject: Re: [PATCH v2 2/4] device.h: move kobj_to_dev() to use container_of_const()
On Mon, Dec 5, 2022 at 1:12 PM Greg Kroah-Hartman
<gregkh@...uxfoundation.org> wrote:
>
> 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@...uxfoundation.org>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: "Rafael J. Wysocki" <rafael@...nel.org>
> Reviewed-by: Jason Gunthorpe <jgg@...dia.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Acked-by: Rafael J. Wysocki <rafael@...nel.org>
> ---
> v2: - respin with changed container_of_const() parameters
>
> include/linux/device.h | 21 +--------------------
> 1 file changed, 1 insertion(+), 20 deletions(-)
>
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 84ae52de6746..8d172d06b8c1 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -680,26 +680,7 @@ 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(__kobj, struct device, kobj)
>
> /**
> * device_iommu_mapped - Returns true when the device DMA is translated
> --
> 2.38.1
>
Powered by blists - more mailing lists