2024-06-11 13:01:40

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

In the quest to make struct device constant, start by making
to_auziliary_drv() return a constant pointer so that drivers that call
this can be fixed up before the driver core changes.

As the return type previously was not constant, also fix up all callers
that were assuming that the pointer was not going to be a constant one
in order to not break the build.

Cc: Greg Kroah-Hartman <[email protected]>
Cc: Dave Ertman <[email protected]>
Cc: Ira Weiny <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Bingbu Cao <[email protected]>
Cc: Tianshu Qiu <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Michael Chan <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Jesse Brandeburg <[email protected]>
Cc: Tony Nguyen <[email protected]>
Cc: Saeed Mahameed <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: Tariq Toukan <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Peter Ujfalusi <[email protected]>
Cc: Bard Liao <[email protected]>
Cc: Ranjani Sridharan <[email protected]>
Cc: Daniel Baluta <[email protected]>
Cc: Kai Vehmanen <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Richard Cochran <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/auxiliary.c | 8 ++++----
drivers/media/pci/intel/ipu6/ipu6-bus.h | 2 +-
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 4 ++--
drivers/net/ethernet/intel/ice/ice_ptp.c | 2 +-
drivers/net/ethernet/mellanox/mlx5/core/dev.c | 4 ++--
include/linux/auxiliary_bus.h | 2 +-
sound/soc/sof/sof-client.c | 4 ++--
7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
index d3a2c40c2f12..5832e31bb77b 100644
--- a/drivers/base/auxiliary.c
+++ b/drivers/base/auxiliary.c
@@ -180,7 +180,7 @@ static const struct auxiliary_device_id *auxiliary_match_id(const struct auxilia
static int auxiliary_match(struct device *dev, struct device_driver *drv)
{
struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
- struct auxiliary_driver *auxdrv = to_auxiliary_drv(drv);
+ const struct auxiliary_driver *auxdrv = to_auxiliary_drv(drv);

return !!auxiliary_match_id(auxdrv->id_table, auxdev);
}
@@ -203,7 +203,7 @@ static const struct dev_pm_ops auxiliary_dev_pm_ops = {

static int auxiliary_bus_probe(struct device *dev)
{
- struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
+ const struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
int ret;

@@ -222,7 +222,7 @@ static int auxiliary_bus_probe(struct device *dev)

static void auxiliary_bus_remove(struct device *dev)
{
- struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
+ const struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
struct auxiliary_device *auxdev = to_auxiliary_dev(dev);

if (auxdrv->remove)
@@ -232,7 +232,7 @@ static void auxiliary_bus_remove(struct device *dev)

static void auxiliary_bus_shutdown(struct device *dev)
{
- struct auxiliary_driver *auxdrv = NULL;
+ const struct auxiliary_driver *auxdrv = NULL;
struct auxiliary_device *auxdev;

if (dev->driver) {
diff --git a/drivers/media/pci/intel/ipu6/ipu6-bus.h b/drivers/media/pci/intel/ipu6/ipu6-bus.h
index b26c6aee1621..bb4926dfdf08 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-bus.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-bus.h
@@ -21,7 +21,7 @@ struct ipu6_buttress_ctrl;

struct ipu6_bus_device {
struct auxiliary_device auxdev;
- struct auxiliary_driver *auxdrv;
+ const struct auxiliary_driver *auxdrv;
const struct ipu6_auxdrv_data *auxdrv_data;
struct list_head list;
void *pdata;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
index ba3fa1c2e5d9..b9e7d3e7b15d 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
@@ -239,7 +239,7 @@ void bnxt_ulp_stop(struct bnxt *bp)

adev = &aux_priv->aux_dev;
if (adev->dev.driver) {
- struct auxiliary_driver *adrv;
+ const struct auxiliary_driver *adrv;
pm_message_t pm = {};

adrv = to_auxiliary_drv(adev->dev.driver);
@@ -277,7 +277,7 @@ void bnxt_ulp_start(struct bnxt *bp, int err)

adev = &aux_priv->aux_dev;
if (adev->dev.driver) {
- struct auxiliary_driver *adrv;
+ const struct auxiliary_driver *adrv;

adrv = to_auxiliary_drv(adev->dev.driver);
edev->en_state = bp->state;
diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
index 0f17fc1181d2..7341e7c4ef24 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -2784,7 +2784,7 @@ static struct ice_pf *
ice_ptp_aux_dev_to_owner_pf(struct auxiliary_device *aux_dev)
{
struct ice_ptp_port_owner *ports_owner;
- struct auxiliary_driver *aux_drv;
+ const struct auxiliary_driver *aux_drv;
struct ice_ptp *owner_ptp;

if (!aux_dev->dev.driver)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
index 47e7c2639774..9a79674d27f1 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
@@ -349,7 +349,7 @@ int mlx5_attach_device(struct mlx5_core_dev *dev)
{
struct mlx5_priv *priv = &dev->priv;
struct auxiliary_device *adev;
- struct auxiliary_driver *adrv;
+ const struct auxiliary_driver *adrv;
int ret = 0, i;

devl_assert_locked(priv_to_devlink(dev));
@@ -406,7 +406,7 @@ void mlx5_detach_device(struct mlx5_core_dev *dev, bool suspend)
{
struct mlx5_priv *priv = &dev->priv;
struct auxiliary_device *adev;
- struct auxiliary_driver *adrv;
+ const struct auxiliary_driver *adrv;
pm_message_t pm = {};
int i;

diff --git a/include/linux/auxiliary_bus.h b/include/linux/auxiliary_bus.h
index de21d9d24a95..bdff7b85f2ae 100644
--- a/include/linux/auxiliary_bus.h
+++ b/include/linux/auxiliary_bus.h
@@ -203,7 +203,7 @@ static inline struct auxiliary_device *to_auxiliary_dev(struct device *dev)
return container_of(dev, struct auxiliary_device, dev);
}

-static inline struct auxiliary_driver *to_auxiliary_drv(struct device_driver *drv)
+static inline const struct auxiliary_driver *to_auxiliary_drv(const struct device_driver *drv)
{
return container_of(drv, struct auxiliary_driver, driver);
}
diff --git a/sound/soc/sof/sof-client.c b/sound/soc/sof/sof-client.c
index 99f74def4ab6..5d6005a88e79 100644
--- a/sound/soc/sof/sof-client.c
+++ b/sound/soc/sof/sof-client.c
@@ -357,7 +357,7 @@ EXPORT_SYMBOL_NS_GPL(sof_client_ipc4_find_module, SND_SOC_SOF_CLIENT);

int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
{
- struct auxiliary_driver *adrv;
+ const struct auxiliary_driver *adrv;
struct sof_client_dev *cdev;

mutex_lock(&sdev->ipc_client_mutex);
@@ -380,7 +380,7 @@ EXPORT_SYMBOL_NS_GPL(sof_suspend_clients, SND_SOC_SOF_CLIENT);

int sof_resume_clients(struct snd_sof_dev *sdev)
{
- struct auxiliary_driver *adrv;
+ const struct auxiliary_driver *adrv;
struct sof_client_dev *cdev;

mutex_lock(&sdev->ipc_client_mutex);
--
2.45.2



2024-06-11 13:02:01

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 4/6] driver core: make device_release_driver_internal() take a const *

Change device_release_driver_internal() to take a const struct
device_driver * as it is not modifying it at all.

Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 2 +-
drivers/base/dd.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index cba8307908c7..d332b87cde9e 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -155,7 +155,7 @@ bool bus_is_registered(const struct bus_type *bus);

int bus_add_driver(struct device_driver *drv);
void bus_remove_driver(struct device_driver *drv);
-void device_release_driver_internal(struct device *dev, struct device_driver *drv,
+void device_release_driver_internal(struct device *dev, const struct device_driver *drv,
struct device *parent);

void driver_detach(struct device_driver *drv);
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 83d352394fdf..c24eca917d41 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1284,7 +1284,7 @@ static void __device_release_driver(struct device *dev, struct device *parent)
}

void device_release_driver_internal(struct device *dev,
- struct device_driver *drv,
+ const struct device_driver *drv,
struct device *parent)
{
__device_driver_lock(dev, parent);
--
2.45.2


2024-06-11 13:02:43

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 5/6] driver core: make driver_detach() take a const *

driver_detach() does not modify the driver itself, so make the pointer
constant. In doing so, the function driver_allows_async_probing() also
needs to be changed so that the pointer type passes through to that
function properly.

Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 2 +-
drivers/base/dd.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index d332b87cde9e..9df8028c3201 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -158,7 +158,7 @@ void bus_remove_driver(struct device_driver *drv);
void device_release_driver_internal(struct device *dev, const struct device_driver *drv,
struct device *parent);

-void driver_detach(struct device_driver *drv);
+void driver_detach(const struct device_driver *drv);
void driver_deferred_probe_del(struct device *dev);
void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf);
static inline int driver_match_device(struct device_driver *drv,
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index c24eca917d41..76b26096b033 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -863,7 +863,7 @@ static int __init save_async_options(char *buf)
}
__setup("driver_async_probe=", save_async_options);

-static bool driver_allows_async_probing(struct device_driver *drv)
+static bool driver_allows_async_probing(const struct device_driver *drv)
{
switch (drv->probe_type) {
case PROBE_PREFER_ASYNCHRONOUS:
@@ -1333,7 +1333,7 @@ void device_driver_detach(struct device *dev)
* driver_detach - detach driver from all devices it controls.
* @drv: driver.
*/
-void driver_detach(struct device_driver *drv)
+void driver_detach(const struct device_driver *drv)
{
struct device_private *dev_prv;
struct device *dev;
--
2.45.2


2024-06-11 13:02:54

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 6/6] driver core: mark async_driver as a const *

Within struct device_private, mark the async_driver * as const as it is
never modified. This requires some internal-to-the-driver-core
functions to also have their parameters marked as constant, and there is
one place where we cast _back_ from the const pointer to a real one, as
the driver core still wants to modify the structure in a number of
remaining places.

Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 2 +-
drivers/base/dd.c | 15 ++++++++-------
2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 9df8028c3201..50151e7db796 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -112,7 +112,7 @@ struct device_private {
struct klist_node knode_bus;
struct klist_node knode_class;
struct list_head deferred_probe;
- struct device_driver *async_driver;
+ const struct device_driver *async_driver;
char *deferred_probe_reason;
struct device *device;
u8 dead:1;
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 76b26096b033..8ec22229e259 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -568,7 +568,7 @@ static void device_remove(struct device *dev)
dev->driver->remove(dev);
}

-static int call_driver_probe(struct device *dev, struct device_driver *drv)
+static int call_driver_probe(struct device *dev, const struct device_driver *drv)
{
int ret = 0;

@@ -599,7 +599,7 @@ static int call_driver_probe(struct device *dev, struct device_driver *drv)
return ret;
}

-static int really_probe(struct device *dev, struct device_driver *drv)
+static int really_probe(struct device *dev, const struct device_driver *drv)
{
bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) &&
!drv->suppress_bind_attrs;
@@ -628,7 +628,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
}

re_probe:
- dev->driver = drv;
+ // FIXME - this cast should not be needed "soon"
+ dev->driver = (struct device_driver *)drv;

/* If using pinctrl, bind pins now before probing */
ret = pinctrl_bind_pins(dev);
@@ -727,7 +728,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
/*
* For initcall_debug, show the driver probe time.
*/
-static int really_probe_debug(struct device *dev, struct device_driver *drv)
+static int really_probe_debug(struct device *dev, const struct device_driver *drv)
{
ktime_t calltime, rettime;
int ret;
@@ -774,7 +775,7 @@ void wait_for_device_probe(void)
}
EXPORT_SYMBOL_GPL(wait_for_device_probe);

-static int __driver_probe_device(struct device_driver *drv, struct device *dev)
+static int __driver_probe_device(const struct device_driver *drv, struct device *dev)
{
int ret = 0;

@@ -819,7 +820,7 @@ static int __driver_probe_device(struct device_driver *drv, struct device *dev)
*
* If the device has a parent, runtime-resume the parent before driver probing.
*/
-static int driver_probe_device(struct device_driver *drv, struct device *dev)
+static int driver_probe_device(const struct device_driver *drv, struct device *dev)
{
int trigger_count = atomic_read(&deferred_trigger_count);
int ret;
@@ -1137,7 +1138,7 @@ EXPORT_SYMBOL_GPL(device_driver_attach);
static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
{
struct device *dev = _dev;
- struct device_driver *drv;
+ const struct device_driver *drv;
int ret;

__device_driver_lock(dev, dev->parent);
--
2.45.2


2024-06-11 13:03:41

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH 3/6] driver core: driver: mark driver_add/remove_groups constant

driver_add_groups() and driver_remove_groups should take a constant
pointer as the structure is not modified, so make the change.

Cc: "Rafael J. Wysocki" <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 4 ++--
drivers/base/driver.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index db4f910e8e36..cba8307908c7 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -175,8 +175,8 @@ static inline void dev_sync_state(struct device *dev)
dev->driver->sync_state(dev);
}

-int driver_add_groups(struct device_driver *drv, const struct attribute_group **groups);
-void driver_remove_groups(struct device_driver *drv, const struct attribute_group **groups);
+int driver_add_groups(const struct device_driver *drv, const struct attribute_group **groups);
+void driver_remove_groups(const struct device_driver *drv, const struct attribute_group **groups);
void device_driver_detach(struct device *dev);

int devres_release_all(struct device *dev);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index c8436c26ed6a..85b4c00df078 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -199,13 +199,13 @@ void driver_remove_file(struct device_driver *drv,
}
EXPORT_SYMBOL_GPL(driver_remove_file);

-int driver_add_groups(struct device_driver *drv,
+int driver_add_groups(const struct device_driver *drv,
const struct attribute_group **groups)
{
return sysfs_create_groups(&drv->p->kobj, groups);
}

-void driver_remove_groups(struct device_driver *drv,
+void driver_remove_groups(const struct device_driver *drv,
const struct attribute_group **groups)
{
sysfs_remove_groups(&drv->p->kobj, groups);
--
2.45.2


2024-06-11 13:37:47

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

On Tue, Jun 11, 2024 at 03:01:04PM +0200, Greg Kroah-Hartman wrote:
> In the quest to make struct device constant, start by making
> to_auziliary_drv() return a constant pointer so that drivers that call
> this can be fixed up before the driver core changes.

Acked-by: Mark Brown <[email protected]>


Attachments:
(No filename) (308.00 B)
signature.asc (499.00 B)
Download all attachments

2024-06-11 13:51:29

by Przemek Kitszel

[permalink] [raw]
Subject: Re: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

On 6/11/24 15:01, Greg Kroah-Hartman wrote:
> In the quest to make struct device constant, start by making

just curious, how far it will go? eg. do you plan to convert
get/put_device() to accept const? or convert devlink API to accept
consts?

> to_auziliary_drv() return a constant pointer so that drivers that call

typo: s/auz/aux/

> this can be fixed up before the driver core changes.
>
> As the return type previously was not constant, also fix up all callers
> that were assuming that the pointer was not going to be a constant one
> in order to not break the build.
>
> Cc: Greg Kroah-Hartman <[email protected]>


[...]

> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index 0f17fc1181d2..7341e7c4ef24 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> @@ -2784,7 +2784,7 @@ static struct ice_pf *
> ice_ptp_aux_dev_to_owner_pf(struct auxiliary_device *aux_dev)
> {
> struct ice_ptp_port_owner *ports_owner;
> - struct auxiliary_driver *aux_drv;
> + const struct auxiliary_driver *aux_drv;
> struct ice_ptp *owner_ptp;
>
> if (!aux_dev->dev.driver)
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> index 47e7c2639774..9a79674d27f1 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> @@ -349,7 +349,7 @@ int mlx5_attach_device(struct mlx5_core_dev *dev)
> {
> struct mlx5_priv *priv = &dev->priv;
> struct auxiliary_device *adev;
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;

nit: in netdev we do maintain RCT order of initialization

> int ret = 0, i;
>
> devl_assert_locked(priv_to_devlink(dev));
> @@ -406,7 +406,7 @@ void mlx5_detach_device(struct mlx5_core_dev *dev, bool suspend)
> {
> struct mlx5_priv *priv = &dev->priv;
> struct auxiliary_device *adev;
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;
> pm_message_t pm = {};
> int i;
>

[...]

2024-06-11 14:00:51

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

On Tue, Jun 11, 2024 at 01:44:07PM +0000, Sakari Ailus wrote:
> Hi Greg,
>
> On Tue, Jun 11, 2024 at 03:01:04PM +0200, Greg Kroah-Hartman wrote:
> > In the quest to make struct device constant, start by making
> > to_auziliary_drv() return a constant pointer so that drivers that call
>
> s/z/s/

Ah, good catch, I'll fix that up when applying it!

> Acked-by: Sakari Ailus <[email protected]> # drivers/media/pci/intel/ipu6

thanks for the review.

greg k-h

2024-06-11 14:15:49

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

On Tue, Jun 11, 2024 at 02:22:37PM +0100, Mark Brown wrote:
> On Tue, Jun 11, 2024 at 03:01:04PM +0200, Greg Kroah-Hartman wrote:
> > In the quest to make struct device constant, start by making
> > to_auziliary_drv() return a constant pointer so that drivers that call
> > this can be fixed up before the driver core changes.
>
> Acked-by: Mark Brown <[email protected]>

thanks for the review.


2024-06-11 17:32:25

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

Hi Greg,

On Tue, Jun 11, 2024 at 03:01:04PM +0200, Greg Kroah-Hartman wrote:
> In the quest to make struct device constant, start by making
> to_auziliary_drv() return a constant pointer so that drivers that call

s/z/s/

Acked-by: Sakari Ailus <[email protected]> # drivers/media/pci/intel/ipu6

> this can be fixed up before the driver core changes.
>
> As the return type previously was not constant, also fix up all callers
> that were assuming that the pointer was not going to be a constant one
> in order to not break the build.

--
Kind regards,

Sakari Ailus

2024-06-12 08:15:28

by Martin Habets

[permalink] [raw]
Subject: Re: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

On Tue, Jun 11, 2024 at 03:01:04PM +0200, Greg Kroah-Hartman wrote:
> In the quest to make struct device constant, start by making
> to_auziliary_drv() return a constant pointer so that drivers that call
> this can be fixed up before the driver core changes.
>
> As the return type previously was not constant, also fix up all callers
> that were assuming that the pointer was not going to be a constant one
> in order to not break the build.
>
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Dave Ertman <[email protected]>
> Cc: Ira Weiny <[email protected]>
> Cc: "Rafael J. Wysocki" <[email protected]>
> Cc: Sakari Ailus <[email protected]>
> Cc: Bingbu Cao <[email protected]>
> Cc: Tianshu Qiu <[email protected]>
> Cc: Mauro Carvalho Chehab <[email protected]>
> Cc: Michael Chan <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: Eric Dumazet <[email protected]>
> Cc: Jakub Kicinski <[email protected]>
> Cc: Paolo Abeni <[email protected]>
> Cc: Jesse Brandeburg <[email protected]>
> Cc: Tony Nguyen <[email protected]>
> Cc: Saeed Mahameed <[email protected]>
> Cc: Leon Romanovsky <[email protected]>
> Cc: Tariq Toukan <[email protected]>
> Cc: Pierre-Louis Bossart <[email protected]>
> Cc: Liam Girdwood <[email protected]>
> Cc: Peter Ujfalusi <[email protected]>
> Cc: Bard Liao <[email protected]>
> Cc: Ranjani Sridharan <[email protected]>
> Cc: Daniel Baluta <[email protected]>
> Cc: Kai Vehmanen <[email protected]>
> Cc: Mark Brown <[email protected]>
> Cc: Jaroslav Kysela <[email protected]>
> Cc: Takashi Iwai <[email protected]>
> Cc: Richard Cochran <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: Martin Habets <[email protected]>

> ---
> drivers/base/auxiliary.c | 8 ++++----
> drivers/media/pci/intel/ipu6/ipu6-bus.h | 2 +-
> drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 4 ++--
> drivers/net/ethernet/intel/ice/ice_ptp.c | 2 +-
> drivers/net/ethernet/mellanox/mlx5/core/dev.c | 4 ++--
> include/linux/auxiliary_bus.h | 2 +-
> sound/soc/sof/sof-client.c | 4 ++--
> 7 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
> index d3a2c40c2f12..5832e31bb77b 100644
> --- a/drivers/base/auxiliary.c
> +++ b/drivers/base/auxiliary.c
> @@ -180,7 +180,7 @@ static const struct auxiliary_device_id *auxiliary_match_id(const struct auxilia
> static int auxiliary_match(struct device *dev, struct device_driver *drv)
> {
> struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
> - struct auxiliary_driver *auxdrv = to_auxiliary_drv(drv);
> + const struct auxiliary_driver *auxdrv = to_auxiliary_drv(drv);
>
> return !!auxiliary_match_id(auxdrv->id_table, auxdev);
> }
> @@ -203,7 +203,7 @@ static const struct dev_pm_ops auxiliary_dev_pm_ops = {
>
> static int auxiliary_bus_probe(struct device *dev)
> {
> - struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
> + const struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
> struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
> int ret;
>
> @@ -222,7 +222,7 @@ static int auxiliary_bus_probe(struct device *dev)
>
> static void auxiliary_bus_remove(struct device *dev)
> {
> - struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
> + const struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver);
> struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
>
> if (auxdrv->remove)
> @@ -232,7 +232,7 @@ static void auxiliary_bus_remove(struct device *dev)
>
> static void auxiliary_bus_shutdown(struct device *dev)
> {
> - struct auxiliary_driver *auxdrv = NULL;
> + const struct auxiliary_driver *auxdrv = NULL;
> struct auxiliary_device *auxdev;
>
> if (dev->driver) {
> diff --git a/drivers/media/pci/intel/ipu6/ipu6-bus.h b/drivers/media/pci/intel/ipu6/ipu6-bus.h
> index b26c6aee1621..bb4926dfdf08 100644
> --- a/drivers/media/pci/intel/ipu6/ipu6-bus.h
> +++ b/drivers/media/pci/intel/ipu6/ipu6-bus.h
> @@ -21,7 +21,7 @@ struct ipu6_buttress_ctrl;
>
> struct ipu6_bus_device {
> struct auxiliary_device auxdev;
> - struct auxiliary_driver *auxdrv;
> + const struct auxiliary_driver *auxdrv;
> const struct ipu6_auxdrv_data *auxdrv_data;
> struct list_head list;
> void *pdata;
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
> index ba3fa1c2e5d9..b9e7d3e7b15d 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
> @@ -239,7 +239,7 @@ void bnxt_ulp_stop(struct bnxt *bp)
>
> adev = &aux_priv->aux_dev;
> if (adev->dev.driver) {
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;
> pm_message_t pm = {};
>
> adrv = to_auxiliary_drv(adev->dev.driver);
> @@ -277,7 +277,7 @@ void bnxt_ulp_start(struct bnxt *bp, int err)
>
> adev = &aux_priv->aux_dev;
> if (adev->dev.driver) {
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;
>
> adrv = to_auxiliary_drv(adev->dev.driver);
> edev->en_state = bp->state;
> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index 0f17fc1181d2..7341e7c4ef24 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> @@ -2784,7 +2784,7 @@ static struct ice_pf *
> ice_ptp_aux_dev_to_owner_pf(struct auxiliary_device *aux_dev)
> {
> struct ice_ptp_port_owner *ports_owner;
> - struct auxiliary_driver *aux_drv;
> + const struct auxiliary_driver *aux_drv;
> struct ice_ptp *owner_ptp;
>
> if (!aux_dev->dev.driver)
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> index 47e7c2639774..9a79674d27f1 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> @@ -349,7 +349,7 @@ int mlx5_attach_device(struct mlx5_core_dev *dev)
> {
> struct mlx5_priv *priv = &dev->priv;
> struct auxiliary_device *adev;
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;
> int ret = 0, i;
>
> devl_assert_locked(priv_to_devlink(dev));
> @@ -406,7 +406,7 @@ void mlx5_detach_device(struct mlx5_core_dev *dev, bool suspend)
> {
> struct mlx5_priv *priv = &dev->priv;
> struct auxiliary_device *adev;
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;
> pm_message_t pm = {};
> int i;
>
> diff --git a/include/linux/auxiliary_bus.h b/include/linux/auxiliary_bus.h
> index de21d9d24a95..bdff7b85f2ae 100644
> --- a/include/linux/auxiliary_bus.h
> +++ b/include/linux/auxiliary_bus.h
> @@ -203,7 +203,7 @@ static inline struct auxiliary_device *to_auxiliary_dev(struct device *dev)
> return container_of(dev, struct auxiliary_device, dev);
> }
>
> -static inline struct auxiliary_driver *to_auxiliary_drv(struct device_driver *drv)
> +static inline const struct auxiliary_driver *to_auxiliary_drv(const struct device_driver *drv)
> {
> return container_of(drv, struct auxiliary_driver, driver);
> }
> diff --git a/sound/soc/sof/sof-client.c b/sound/soc/sof/sof-client.c
> index 99f74def4ab6..5d6005a88e79 100644
> --- a/sound/soc/sof/sof-client.c
> +++ b/sound/soc/sof/sof-client.c
> @@ -357,7 +357,7 @@ EXPORT_SYMBOL_NS_GPL(sof_client_ipc4_find_module, SND_SOC_SOF_CLIENT);
>
> int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
> {
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;
> struct sof_client_dev *cdev;
>
> mutex_lock(&sdev->ipc_client_mutex);
> @@ -380,7 +380,7 @@ EXPORT_SYMBOL_NS_GPL(sof_suspend_clients, SND_SOC_SOF_CLIENT);
>
> int sof_resume_clients(struct snd_sof_dev *sdev)
> {
> - struct auxiliary_driver *adrv;
> + const struct auxiliary_driver *adrv;
> struct sof_client_dev *cdev;
>
> mutex_lock(&sdev->ipc_client_mutex);
> --
> 2.45.2
>

2024-06-12 08:29:57

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/6] auxbus: make to_auxiliary_drv accept and return a constant pointer

On Tue, Jun 11, 2024 at 03:50:47PM +0200, Przemek Kitszel wrote:
> On 6/11/24 15:01, Greg Kroah-Hartman wrote:
> > In the quest to make struct device constant, start by making
>
> just curious, how far it will go? eg. do you plan to convert
> get/put_device() to accept const?

Ugh, that should have said "in the quest to make struct device_driver
const", not device. devices obviously can't be constant everywhere as
they are dynamically created.

> or convert devlink API to accept
> consts?

Again, sorry, no, typo on my part.

>
> > to_auziliary_drv() return a constant pointer so that drivers that call
>
> typo: s/auz/aux/

I'll fix this typo up, and the one above, when I commit it.

>
> > this can be fixed up before the driver core changes.
> >
> > As the return type previously was not constant, also fix up all callers
> > that were assuming that the pointer was not going to be a constant one
> > in order to not break the build.
> >
> > Cc: Greg Kroah-Hartman <[email protected]>
>
>
> [...]
>
> > diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> > index 0f17fc1181d2..7341e7c4ef24 100644
> > --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> > +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> > @@ -2784,7 +2784,7 @@ static struct ice_pf *
> > ice_ptp_aux_dev_to_owner_pf(struct auxiliary_device *aux_dev)
> > {
> > struct ice_ptp_port_owner *ports_owner;
> > - struct auxiliary_driver *aux_drv;
> > + const struct auxiliary_driver *aux_drv;
> > struct ice_ptp *owner_ptp;
> > if (!aux_dev->dev.driver)
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> > index 47e7c2639774..9a79674d27f1 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
> > @@ -349,7 +349,7 @@ int mlx5_attach_device(struct mlx5_core_dev *dev)
> > {
> > struct mlx5_priv *priv = &dev->priv;
> > struct auxiliary_device *adev;
> > - struct auxiliary_driver *adrv;
> > + const struct auxiliary_driver *adrv;
>
> nit: in netdev we do maintain RCT order of initialization

what does that mean? Nothing is being initialized here.

thanks,

greg k-h