diff mbox series

[RFC,v5,2/4] driver core: Add dev_is_drv_state_synced()

Message ID 20230621144019.3219858-3-abel.vesa@linaro.org (mailing list archive)
State Not Applicable
Headers show
Series PM: domain: Support skiping disabling unused domains until sync state | expand

Commit Message

Abel Vesa June 21, 2023, 2:40 p.m. UTC
This can be used by drivers to figure out if a different device
driver has state synced or not for a specific device.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 include/linux/device.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Greg Kroah-Hartman June 21, 2023, 3:22 p.m. UTC | #1
On Wed, Jun 21, 2023 at 05:40:17PM +0300, Abel Vesa wrote:
> This can be used by drivers to figure out if a different device
> driver has state synced or not for a specific device.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  include/linux/device.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/include/linux/device.h b/include/linux/device.h
> index bae11928ef7e..8f042f04b5d9 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -1007,6 +1007,20 @@ static inline int dev_set_drv_sync_state(struct device *dev,
>  	return 0;
>  }
>  
> +static inline bool dev_is_drv_state_synced(struct device *dev)
> +{
> +	bool ret = false;
> +
> +	if (!dev)
> +		return ret;
> +
> +	device_lock(dev);
> +	ret = dev->state_synced;
> +	device_unlock(dev);

This lock is "protecting" nothing, given that the value can instantly
change after it is read.

Because it can change, how will this function actually show anything
relevant?

thanks,

greg k-h
Abel Vesa June 28, 2023, 11:50 a.m. UTC | #2
On 23-06-21 17:22:54, Greg Kroah-Hartman wrote:
> On Wed, Jun 21, 2023 at 05:40:17PM +0300, Abel Vesa wrote:
> > This can be used by drivers to figure out if a different device
> > driver has state synced or not for a specific device.
> > 
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > ---
> >  include/linux/device.h | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/include/linux/device.h b/include/linux/device.h
> > index bae11928ef7e..8f042f04b5d9 100644
> > --- a/include/linux/device.h
> > +++ b/include/linux/device.h
> > @@ -1007,6 +1007,20 @@ static inline int dev_set_drv_sync_state(struct device *dev,
> >  	return 0;
> >  }
> >  
> > +static inline bool dev_is_drv_state_synced(struct device *dev)
> > +{
> > +	bool ret = false;
> > +
> > +	if (!dev)
> > +		return ret;
> > +
> > +	device_lock(dev);
> > +	ret = dev->state_synced;
> > +	device_unlock(dev);
> 
> This lock is "protecting" nothing, given that the value can instantly
> change after it is read.

Hmm, for some reason I thought it needs to be synchronized with the
sync state callback being called already. But I just noticed that call
to the sync state callback is independently locked after state_synced is
set. So I guess the lock can go away here.

> 
> Because it can change, how will this function actually show anything
> relevant?

The only usecase I can think of for this new API is for some driver
to delay an action until ultimately the driver for a specific device
gets state synced. So even if the value can change after it has
been checked, such consumer driver will most likely retry later on.

Hope that makes sense.

> 
> thanks,
> 
> greg k-h
diff mbox series

Patch

diff --git a/include/linux/device.h b/include/linux/device.h
index bae11928ef7e..8f042f04b5d9 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1007,6 +1007,20 @@  static inline int dev_set_drv_sync_state(struct device *dev,
 	return 0;
 }
 
+static inline bool dev_is_drv_state_synced(struct device *dev)
+{
+	bool ret = false;
+
+	if (!dev)
+		return ret;
+
+	device_lock(dev);
+	ret = dev->state_synced;
+	device_unlock(dev);
+
+	return ret;
+}
+
 static inline void dev_set_removable(struct device *dev,
 				     enum device_removable removable)
 {