Thread (26 messages) 26 messages, 9 authors, 2023-01-11

Re: [PATCH 3/5] driver core: make struct device_type.uevent() take a const *

From: Maximilian Luz <luzmaximilian@gmail.com>
Date: 2022-11-23 13:33:02
Also in: alsa-devel, linux-acpi, linux-block, linux-devicetree, linux-i2c, linux-i3c, linux-media, linux-serial, linux-usb, lkml, platform-driver-x86

Hi,

On 11/23/22 13:25, Greg Kroah-Hartman wrote:
The uevent() callback in struct device_type should not be modifying the
device that is passed into it, so mark it as a const * and propagate the
function signature changes out into all relevant subsystems that use
this callback.
[...]
quoted hunk ↗ jump to hunk
diff --git a/drivers/platform/surface/aggregator/bus.c b/drivers/platform/surface/aggregator/bus.c
index de539938896e..407eb55050a6 100644
--- a/drivers/platform/surface/aggregator/bus.c
+++ b/drivers/platform/surface/aggregator/bus.c
@@ -35,9 +35,9 @@ static struct attribute *ssam_device_attrs[] = {
  };
  ATTRIBUTE_GROUPS(ssam_device);
  
-static int ssam_device_uevent(struct device *dev, struct kobj_uevent_env *env)
+static int ssam_device_uevent(const struct device *dev, struct kobj_uevent_env *env)
  {
-	struct ssam_device *sdev = to_ssam_device(dev);
+	const struct ssam_device *sdev = to_ssam_device(dev);
  
  	return add_uevent_var(env, "MODALIAS=ssam:d%02Xc%02Xt%02Xi%02Xf%02X",
  			      sdev->uid.domain, sdev->uid.category,
[...]
quoted hunk ↗ jump to hunk
--- a/include/linux/surface_aggregator/device.h
+++ b/include/linux/surface_aggregator/device.h
@@ -229,7 +229,7 @@ static inline bool is_ssam_device(struct device *d)
   * Return: Returns a pointer to the &struct ssam_device wrapping the given
   * device @d.
   */
-static inline struct ssam_device *to_ssam_device(struct device *d)
+static inline struct ssam_device *to_ssam_device(const struct device *d)
  {
  	return container_of(d, struct ssam_device, dev);
  }
I am slightly conflicted about this change as that now more or less
implicitly drops the const. So I'm wondering if it wouldn't be better to
either create a function specifically for const pointers or to just
open-code it in the instance above.

I guess we could also convert this to a macro. Then at least there
wouldn't be an explicit and potentially misleading const-conversion
indicated in the function signature.

Regards,
Max
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help