Introduce conditional guard version of device_lock() for scenarios that
require conditional device lock holding.
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Li Ming <ming.li@zohomail.com>
---
include/linux/device.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/device.h b/include/linux/device.h
index 0be95294b6e6..4fafee80524b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev)
}
DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T))
+DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0)
static inline void device_lock_assert(struct device *dev)
{
--
2.43.0
On Tue Mar 10, 2026 at 4:57 PM CET, Li Ming wrote: > Introduce conditional guard version of device_lock() for scenarios that > require conditional device lock holding. > > Suggested-by: Dan Williams <dan.j.williams@intel.com> > Signed-off-by: Li Ming <ming.li@zohomail.com> Applied to driver-core-next, thanks! As dicussed, here's the signed tag: https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/tag/?h=device_lock_cond_guard-7.1-rc1 Thanks, Danilo
On Tue, Mar 10, 2026 at 11:57:53PM +0800, Li Ming wrote:
> Introduce conditional guard version of device_lock() for scenarios that
> require conditional device lock holding.
>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Li Ming <ming.li@zohomail.com>
> ---
> include/linux/device.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 0be95294b6e6..4fafee80524b 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev)
> }
>
> DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T))
> +DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0)
>
> static inline void device_lock_assert(struct device *dev)
> {
>
> --
> 2.43.0
>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
On 3/10/26 8:57 AM, Li Ming wrote:
> Introduce conditional guard version of device_lock() for scenarios that
> require conditional device lock holding.
>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Li Ming <ming.li@zohomail.com>
> ---
> include/linux/device.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 0be95294b6e6..4fafee80524b 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev)
> }
>
> DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T))
> +DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0)
Can you please just squash this small change to the same patch that is using it? Thanks!
>
> static inline void device_lock_assert(struct device *dev)
> {
>
On Tue Mar 10, 2026 at 6:45 PM CET, Dave Jiang wrote: > On 3/10/26 8:57 AM, Li Ming wrote: >> Introduce conditional guard version of device_lock() for scenarios that >> require conditional device lock holding. >> >> Suggested-by: Dan Williams <dan.j.williams@intel.com> >> Signed-off-by: Li Ming <ming.li@zohomail.com> >> --- >> include/linux/device.h | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/include/linux/device.h b/include/linux/device.h >> index 0be95294b6e6..4fafee80524b 100644 >> --- a/include/linux/device.h >> +++ b/include/linux/device.h >> @@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev) >> } >> >> DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T)) >> +DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0) > > Can you please just squash this small change to the same patch that is using it? Thanks! Why? It is a single logical change and hence should be a separate patch, no? We even tell contributors in the documentation [1] that adding new APIs and using them should be separate patches. Additionally, in this case it affects another subsystem, so it also makes sense in terms of making the change obvious to the maintainers of the other subsystem. [1] https://docs.kernel.org/process/submitting-patches.html#separate-your-changes
On 3/10/26 11:06 AM, Danilo Krummrich wrote: > On Tue Mar 10, 2026 at 6:45 PM CET, Dave Jiang wrote: >> On 3/10/26 8:57 AM, Li Ming wrote: >>> Introduce conditional guard version of device_lock() for scenarios that >>> require conditional device lock holding. >>> >>> Suggested-by: Dan Williams <dan.j.williams@intel.com> >>> Signed-off-by: Li Ming <ming.li@zohomail.com> >>> --- >>> include/linux/device.h | 1 + >>> 1 file changed, 1 insertion(+) >>> >>> diff --git a/include/linux/device.h b/include/linux/device.h >>> index 0be95294b6e6..4fafee80524b 100644 >>> --- a/include/linux/device.h >>> +++ b/include/linux/device.h >>> @@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev) >>> } >>> >>> DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T)) >>> +DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0) >> >> Can you please just squash this small change to the same patch that is using it? Thanks! > > Why? It is a single logical change and hence should be a separate patch, no? For some reason I missed it's in linux/device.h. So sure ok. But typically I would like to see the usage if it's in the same sub-system. DJ > > We even tell contributors in the documentation [1] that adding new APIs and > using them should be separate patches. > > Additionally, in this case it affects another subsystem, so it also makes sense > in terms of making the change obvious to the maintainers of the other subsystem. > > [1] https://docs.kernel.org/process/submitting-patches.html#separate-your-changes
Dave Jiang wrote: [..] > >>> diff --git a/include/linux/device.h b/include/linux/device.h > >>> index 0be95294b6e6..4fafee80524b 100644 > >>> --- a/include/linux/device.h > >>> +++ b/include/linux/device.h > >>> @@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev) > >>> } > >>> > >>> DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T)) > >>> +DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0) > >> > >> Can you please just squash this small change to the same patch that is using it? Thanks! > > > > Why? It is a single logical change and hence should be a separate patch, no? > > For some reason I missed it's in linux/device.h. So sure ok. But > typically I would like to see the usage if it's in the same > sub-system. I generally expect the same as well. ...however, when we get into multiple in flight patch sets wanting the same API [1] it would be nice to have a stable commit id to share, Greg? [1]: TEE I/O enabling also has a use case, and introduced the helper with the "first" user. http://lore.kernel.org/20260303000207.1836586-7-dan.j.williams@intel.com
On Tue Mar 10, 2026 at 7:39 PM CET, Dan Williams wrote: > Dave Jiang wrote: > [..] >> >>> diff --git a/include/linux/device.h b/include/linux/device.h >> >>> index 0be95294b6e6..4fafee80524b 100644 >> >>> --- a/include/linux/device.h >> >>> +++ b/include/linux/device.h >> >>> @@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev) >> >>> } >> >>> >> >>> DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T)) >> >>> +DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0) >> >> >> >> Can you please just squash this small change to the same patch that is using it? Thanks! >> > >> > Why? It is a single logical change and hence should be a separate patch, no? >> >> For some reason I missed it's in linux/device.h. So sure ok. But >> typically I would like to see the usage if it's in the same >> sub-system. > > I generally expect the same as well. > > ...however, when we get into multiple in flight patch sets wanting the > same API [1] it would be nice to have a stable commit id to share, Greg? > > [1]: TEE I/O enabling also has a use case, and introduced the helper > with the "first" user. > http://lore.kernel.org/20260303000207.1836586-7-dan.j.williams@intel.com This patch has neither Rafael, me nor the driver-core mailing list Cc'd and buries this change in a patch named "PCI/TSM: Add Device Security (TVM Guest) LOCK operation support", which makes pretty it hard to catch. Please submit such changes as a separate patch and send it to all maintainers and the corresponding mailing list such that people have a chance to take note of it. As for sharing the commit throughout multiple trees, I can provide a signed tag similar to [1] once Greg and Rafael had a chance to take a look at this patch as well. You may also want to sort out authorship / tags with Li. Thanks, Danilo [1] https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/tag/?h=platform_device_info_swnode-7.1-rc1
Danilo Krummrich wrote: [..] > As for sharing the commit throughout multiple trees, I can provide a signed tag > similar to [1] once Greg and Rafael had a chance to take a look at this patch as > well. That would be lovely, thank you. Please take this patch. Reviewed-by: Dan Williams <dan.j.williams@intel.com> > You may also want to sort out authorship / tags with Li. No worries about authorship for something so tiny. Also, I misremembered that I sent the base device_lock() guard as a standalone patch rather than with the first user. [1]: 134c6eaa6087 driver core: Add a guard() definition for the device_lock()
On Tue Mar 10, 2026 at 9:37 PM CET, Dan Williams wrote: > Danilo Krummrich wrote: > [..] >> As for sharing the commit throughout multiple trees, I can provide a signed tag >> similar to [1] once Greg and Rafael had a chance to take a look at this patch as >> well. > > That would be lovely, thank you. Please take this patch. > > Reviewed-by: Dan Williams <dan.j.williams@intel.com> Thanks! >> You may also want to sort out authorship / tags with Li. > > No worries about authorship for something so tiny. Neither would I, but I'd rather make sure. :)
© 2016 - 2026 Red Hat, Inc.