[PATCH] drm/fb-helper: Fix a locking bug in an error path

Bart Van Assche posted 1 patch 2 months, 1 week ago
drivers/gpu/drm/drm_fb_helper.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] drm/fb-helper: Fix a locking bug in an error path
Posted by Bart Van Assche 2 months, 1 week ago
The name of the function __drm_fb_helper_initial_config_and_unlock() and
also the comment above that function make it clear that all code paths
in this function should unlock fb_helper->lock before returning. Add a
mutex_unlock() call in the only code path where it is missing. This has
been detected by the Clang thread-safety analyzer.

Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Christian König <christian.koenig@amd.com> # radeon
Cc: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> # msm
Cc: Javier Martinez Canillas <javierm@redhat.com>
Fixes: 63c971af4036 ("drm/fb-helper: Allocate and release fb_info in single place")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/gpu/drm/drm_fb_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 05803169bed5..16bfbfb0af16 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -1641,8 +1641,10 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper)
 	drm_client_modeset_probe(&fb_helper->client, width, height);
 
 	info = drm_fb_helper_alloc_info(fb_helper);
-	if (IS_ERR(info))
+	if (IS_ERR(info)) {
+		mutex_unlock(&fb_helper->lock);
 		return PTR_ERR(info);
+	}
 
 	ret = drm_fb_helper_single_fb_probe(fb_helper);
 	if (ret < 0) {
Re: [PATCH] drm/fb-helper: Fix a locking bug in an error path
Posted by Javier Martinez Canillas 2 months ago
Bart Van Assche <bvanassche@acm.org> writes:

> The name of the function __drm_fb_helper_initial_config_and_unlock() and
> also the comment above that function make it clear that all code paths
> in this function should unlock fb_helper->lock before returning. Add a
> mutex_unlock() call in the only code path where it is missing. This has
> been detected by the Clang thread-safety analyzer.
>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Christian König <christian.koenig@amd.com> # radeon
> Cc: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> # msm
> Cc: Javier Martinez Canillas <javierm@redhat.com>
> Fixes: 63c971af4036 ("drm/fb-helper: Allocate and release fb_info in single place")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---

Indeed, thanks for fixing this.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
Re: [PATCH] drm/fb-helper: Fix a locking bug in an error path
Posted by Thomas Zimmermann 2 months, 1 week ago
Hi

Am 03.04.26 um 22:53 schrieb Bart Van Assche:
> The name of the function __drm_fb_helper_initial_config_and_unlock() and
> also the comment above that function make it clear that all code paths
> in this function should unlock fb_helper->lock before returning. Add a
> mutex_unlock() call in the only code path where it is missing. This has
> been detected by the Clang thread-safety analyzer.
>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Christian König <christian.koenig@amd.com> # radeon
> Cc: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> # msm
> Cc: Javier Martinez Canillas <javierm@redhat.com>
> Fixes: 63c971af4036 ("drm/fb-helper: Allocate and release fb_info in single place")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

Thanks a lot.

Best regards
Thomas

> ---
>   drivers/gpu/drm/drm_fb_helper.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index 05803169bed5..16bfbfb0af16 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -1641,8 +1641,10 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper)
>   	drm_client_modeset_probe(&fb_helper->client, width, height);
>   
>   	info = drm_fb_helper_alloc_info(fb_helper);
> -	if (IS_ERR(info))
> +	if (IS_ERR(info)) {
> +		mutex_unlock(&fb_helper->lock);
>   		return PTR_ERR(info);
> +	}
>   
>   	ret = drm_fb_helper_single_fb_probe(fb_helper);
>   	if (ret < 0) {

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)


Re: [PATCH] drm/fb-helper: Fix a locking bug in an error path
Posted by Thomas Zimmermann 2 months, 1 week ago
(cc: dri-devel)

Am 07.04.26 um 09:44 schrieb Thomas Zimmermann:
> Hi
>
> Am 03.04.26 um 22:53 schrieb Bart Van Assche:
>> The name of the function __drm_fb_helper_initial_config_and_unlock() and
>> also the comment above that function make it clear that all code paths
>> in this function should unlock fb_helper->lock before returning. Add a
>> mutex_unlock() call in the only code path where it is missing. This has
>> been detected by the Clang thread-safety analyzer.
>>
>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>> Cc: Christian König <christian.koenig@amd.com> # radeon
>> Cc: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> # msm
>> Cc: Javier Martinez Canillas <javierm@redhat.com>
>> Fixes: 63c971af4036 ("drm/fb-helper: Allocate and release fb_info in 
>> single place")
>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
>
> Thanks a lot.
>
> Best regards
> Thomas
>
>> ---
>>   drivers/gpu/drm/drm_fb_helper.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/drm_fb_helper.c 
>> b/drivers/gpu/drm/drm_fb_helper.c
>> index 05803169bed5..16bfbfb0af16 100644
>> --- a/drivers/gpu/drm/drm_fb_helper.c
>> +++ b/drivers/gpu/drm/drm_fb_helper.c
>> @@ -1641,8 +1641,10 @@ 
>> __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper 
>> *fb_helper)
>>       drm_client_modeset_probe(&fb_helper->client, width, height);
>>         info = drm_fb_helper_alloc_info(fb_helper);
>> -    if (IS_ERR(info))
>> +    if (IS_ERR(info)) {
>> +        mutex_unlock(&fb_helper->lock);
>>           return PTR_ERR(info);
>> +    }
>>         ret = drm_fb_helper_single_fb_probe(fb_helper);
>>       if (ret < 0) {
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)


Re: [PATCH] drm/fb-helper: Fix a locking bug in an error path
Posted by Bart Van Assche 2 months, 1 week ago
On 4/7/26 12:47 AM, Thomas Zimmermann wrote:
> (cc: dri-devel)

Hi Thomas,

Is dri-devel the right mailing list to Cc for this patch? If so, how 
about adding an L: line to the drivers/gpu/drm/ entry in the MAINTAINERS
file? That entry currently doesn't have an L: line as one can see below:

DRM DRIVERS AND MISC GPU PATCHES
M:	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
M:	Maxime Ripard <mripard@kernel.org>
M:	Thomas Zimmermann <tzimmermann@suse.de>
S:	Maintained
W:	https://drm.pages.freedesktop.org/maintainer-tools/drm-misc.html
T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
F:	Documentation/devicetree/bindings/display/
F:	Documentation/devicetree/bindings/gpu/
F:	Documentation/gpu/
F:	drivers/gpu/drm/
F:	drivers/gpu/vga/
F:	include/drm/drm
F:	include/linux/vga*
F:	include/uapi/drm/
X:	drivers/gpu/drm/amd/
X:	drivers/gpu/drm/armada/
X:	drivers/gpu/drm/etnaviv/
X:	drivers/gpu/drm/exynos/
X:	drivers/gpu/drm/i915/
X:	drivers/gpu/drm/kmb/
X:	drivers/gpu/drm/mediatek/
X:	drivers/gpu/drm/msm/
X:	drivers/gpu/drm/nova/
X:	drivers/gpu/drm/radeon/
X:	drivers/gpu/drm/tegra/
X:	drivers/gpu/drm/tyr/
X:	drivers/gpu/drm/xe/

Thanks,

Bart.
Re: [PATCH] drm/fb-helper: Fix a locking bug in an error path
Posted by Thomas Zimmermann 2 months, 1 week ago
Hi

Am 07.04.26 um 17:17 schrieb Bart Van Assche:
> On 4/7/26 12:47 AM, Thomas Zimmermann wrote:
>> (cc: dri-devel)
>
> Hi Thomas,
>
> Is dri-devel the right mailing list to Cc for this patch? If so, how 
> about adding an L: line to the drivers/gpu/drm/ entry in the MAINTAINERS
> file? That entry currently doesn't have an L: line as one can see below:

It is covered by the general "DRM DRIVERS" entry and tools seem to get 
it right.

But yeah, that L: entry seems missing here. And it's so obviously 
missing that I wonder if it's intentional.

Best regards
Thomas


>
> DRM DRIVERS AND MISC GPU PATCHES
> M:    Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> M:    Maxime Ripard <mripard@kernel.org>
> M:    Thomas Zimmermann <tzimmermann@suse.de>
> S:    Maintained
> W: https://drm.pages.freedesktop.org/maintainer-tools/drm-misc.html
> T:    git https://gitlab.freedesktop.org/drm/misc/kernel.git
> F:    Documentation/devicetree/bindings/display/
> F:    Documentation/devicetree/bindings/gpu/
> F:    Documentation/gpu/
> F:    drivers/gpu/drm/
> F:    drivers/gpu/vga/
> F:    include/drm/drm
> F:    include/linux/vga*
> F:    include/uapi/drm/
> X:    drivers/gpu/drm/amd/
> X:    drivers/gpu/drm/armada/
> X:    drivers/gpu/drm/etnaviv/
> X:    drivers/gpu/drm/exynos/
> X:    drivers/gpu/drm/i915/
> X:    drivers/gpu/drm/kmb/
> X:    drivers/gpu/drm/mediatek/
> X:    drivers/gpu/drm/msm/
> X:    drivers/gpu/drm/nova/
> X:    drivers/gpu/drm/radeon/
> X:    drivers/gpu/drm/tegra/
> X:    drivers/gpu/drm/tyr/
> X:    drivers/gpu/drm/xe/
>
> Thanks,
>
> Bart.

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)