From nobody Fri Jun 19 07:17:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19EDEC433EF for ; Wed, 6 Apr 2022 17:55:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239862AbiDFR5R (ORCPT ); Wed, 6 Apr 2022 13:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239745AbiDFR5F (ORCPT ); Wed, 6 Apr 2022 13:57:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 24E44195335 for ; Wed, 6 Apr 2022 09:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649261207; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dwo5m09InEiwEv2dnAvGc2fVvZ9j801adW/M2Xiq7pU=; b=BKQq5PEP1z1qh8fZH/VUtO4wDm78JUIrVY3Mmipu4YqgpCcLhJnYLLMYaMX2gRniX9Zc6T Myq0mKPEu5F/MsojDhLk2Z4wXwIykJXD91h23fBzCdFH2G4JzX6xc37OgD/Y7f0Xe/zhWS 5vQXpyfcRc4jOqCffqDg47nCPXyQZVY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-XiYxRRgbNoSCkc8RUgxoGQ-1; Wed, 06 Apr 2022 12:06:46 -0400 X-MC-Unique: XiYxRRgbNoSCkc8RUgxoGQ-1 Received: by mail-wm1-f70.google.com with SMTP id f19-20020a7bcd13000000b0038c01defd5aso1508853wmj.7 for ; Wed, 06 Apr 2022 09:06:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dwo5m09InEiwEv2dnAvGc2fVvZ9j801adW/M2Xiq7pU=; b=bJ/rGo+U1jx3GFEdlyNQi6Gb7gN/aealU57vr5rTXFiU7gG7GxEfIc6wQblgPFMQxc VnVmRRNMNLgFhQq9eCd6tzmfUSxB/81KWjIY/oYdaIaeGjnxXn6p8PTnsohdz99Pf4+j w1fpP8+9bBbK00dX2ez1Z7NXj1LwbSnmDoswvdmm2rLwd9vHbdi+M5C2s2UtWCXdjDPg WXQnqKCa90QkbLdvy957Vg/H7TH4zPv+ASQm/tH2LV04sx/ZT5LmaC/fg73o1acmvlfQ OJnvA3KQ16DlwzOdeF3K45awa6xF2G1FTb4ox/pksTILIDSlHqx+ohdcLnys/Gl/jUnU VWaw== X-Gm-Message-State: AOAM532g9Jsxdb5Nchg0mQ7BJw9vfpRjbFDO40stOWK2OXLrgWsjyfhS plB/RK8hy1p3dg8FRsWzM6K19poeguhpheojoGvNmewTKTHB8/j4exLOpZZCVNzwV5PCKTDWe1r ioYhREJZ9Pj5YkElmxymr9P0r//aqt7Ame3zDwht7SS9C3Mm1Rv8Q/oruXe3PQxEQQVkEJqzmia 8= X-Received: by 2002:a7b:c24c:0:b0:38e:7a15:e349 with SMTP id b12-20020a7bc24c000000b0038e7a15e349mr8455839wmj.61.1649261204665; Wed, 06 Apr 2022 09:06:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKgteymNh0bGfGN9dBE7n8RnKDuoLaQSMbadEdsd2ly2Big0ojbEqQxEsrhTDZom3yXvjizg== X-Received: by 2002:a7b:c24c:0:b0:38e:7a15:e349 with SMTP id b12-20020a7bc24c000000b0038e7a15e349mr8455808wmj.61.1649261204358; Wed, 06 Apr 2022 09:06:44 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f1-20020a1c6a01000000b0038c9f6a3634sm5038899wmc.7.2022.04.06.09.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:06:44 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Thomas Zimmermann , Daniel Vetter , Javier Martinez Canillas , Borislav Petkov , Greg Kroah-Hartman , Miaoqian Lin Subject: [RFC PATCH 1/5] firmware: sysfb: Make sysfb_create_simplefb() return a pdev pointer Date: Wed, 6 Apr 2022 18:06:28 +0200 Message-Id: <20220406160632.496684-2-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406160632.496684-1-javierm@redhat.com> References: <20220406160632.496684-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This function just returned 0 on success or an errno code on error, but it could be useful to sysfb_init() to get a pointer to the device registered. Signed-off-by: Javier Martinez Canillas --- drivers/firmware/sysfb.c | 4 ++-- drivers/firmware/sysfb_simplefb.c | 24 +++++++++++++++--------- include/linux/sysfb.h | 8 ++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/drivers/firmware/sysfb.c b/drivers/firmware/sysfb.c index 2bfbb05f7d89..b032f40a92de 100644 --- a/drivers/firmware/sysfb.c +++ b/drivers/firmware/sysfb.c @@ -46,8 +46,8 @@ static __init int sysfb_init(void) /* try to create a simple-framebuffer device */ compatible =3D sysfb_parse_mode(si, &mode); if (compatible) { - ret =3D sysfb_create_simplefb(si, &mode); - if (!ret) + pd =3D sysfb_create_simplefb(si, &mode); + if (!IS_ERR(pd)) return 0; } =20 diff --git a/drivers/firmware/sysfb_simplefb.c b/drivers/firmware/sysfb_sim= plefb.c index 76c4abc42a30..c42648ed3aad 100644 --- a/drivers/firmware/sysfb_simplefb.c +++ b/drivers/firmware/sysfb_simplefb.c @@ -57,8 +57,8 @@ __init bool sysfb_parse_mode(const struct screen_info *si, return false; } =20 -__init int sysfb_create_simplefb(const struct screen_info *si, - const struct simplefb_platform_data *mode) +__init struct platform_device *sysfb_create_simplefb(const struct screen_i= nfo *si, + const struct simplefb_platform_data *mode) { struct platform_device *pd; struct resource res; @@ -76,7 +76,7 @@ __init int sysfb_create_simplefb(const struct screen_info= *si, base |=3D (u64)si->ext_lfb_base << 32; if (!base || (u64)(resource_size_t)base !=3D base) { printk(KERN_DEBUG "sysfb: inaccessible VRAM base\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } =20 /* @@ -93,7 +93,7 @@ __init int sysfb_create_simplefb(const struct screen_info= *si, length =3D mode->height * mode->stride; if (length > size) { printk(KERN_WARNING "sysfb: VRAM smaller than advertised\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } length =3D PAGE_ALIGN(length); =20 @@ -104,25 +104,31 @@ __init int sysfb_create_simplefb(const struct screen_= info *si, res.start =3D base; res.end =3D res.start + length - 1; if (res.end <=3D res.start) - return -EINVAL; + return ERR_PTR(-EINVAL); =20 pd =3D platform_device_alloc("simple-framebuffer", 0); if (!pd) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 sysfb_apply_efi_quirks(pd); =20 ret =3D platform_device_add_resources(pd, &res, 1); if (ret) { platform_device_put(pd); - return ret; + return ERR_PTR(ret); } =20 ret =3D platform_device_add_data(pd, mode, sizeof(*mode)); if (ret) { platform_device_put(pd); - return ret; + return ERR_PTR(ret); } =20 - return platform_device_add(pd); + ret =3D platform_device_add(pd); + if (ret) { + platform_device_put(pd); + return ERR_PTR(ret); + } + + return pd; } diff --git a/include/linux/sysfb.h b/include/linux/sysfb.h index b0dcfa26d07b..9857518f4cdd 100644 --- a/include/linux/sysfb.h +++ b/include/linux/sysfb.h @@ -72,8 +72,8 @@ static inline void sysfb_apply_efi_quirks(struct platform= _device *pd) =20 bool sysfb_parse_mode(const struct screen_info *si, struct simplefb_platform_data *mode); -int sysfb_create_simplefb(const struct screen_info *si, - const struct simplefb_platform_data *mode); +struct platform_device *sysfb_create_simplefb(const struct screen_info *si, + const struct simplefb_platform_data *mode); =20 #else /* CONFIG_SYSFB_SIMPLE */ =20 @@ -83,8 +83,8 @@ static inline bool sysfb_parse_mode(const struct screen_i= nfo *si, return false; } =20 -static inline int sysfb_create_simplefb(const struct screen_info *si, - const struct simplefb_platform_data *mode) +static inline struct platform_device *sysfb_create_simplefb(const struct s= creen_info *si, + const struct simplefb_platform_data *mode) { return -EINVAL; } --=20 2.35.1 From nobody Fri Jun 19 07:17:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E8A3C4332F for ; Wed, 6 Apr 2022 17:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239881AbiDFR5i (ORCPT ); Wed, 6 Apr 2022 13:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239752AbiDFR5G (ORCPT ); Wed, 6 Apr 2022 13:57:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1FEF7196083 for ; Wed, 6 Apr 2022 09:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649261208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gnVQUL3ppm1TNC7utGALyGd2EAWXx63qYM1Qkn/cJqo=; b=MuV7334vlIWYXSmVtBfmVi34AVFIlpXf5F0IrFc8AaL2cXjpEV1So9h4Mws4xTNNOHwy2t jC+PZZ4vDahvkx4MAZX7jZiYSqeXMRVk1zTL259QEzxOcdxgyDha+GO9TSNBFti4WZivgp j28R+xpf0sjdPWb/iTqkHgcTPNvfb5Q= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-_o-iFnlpMo2SdvaJ8OKCUw-1; Wed, 06 Apr 2022 12:06:47 -0400 X-MC-Unique: _o-iFnlpMo2SdvaJ8OKCUw-1 Received: by mail-wm1-f71.google.com with SMTP id z16-20020a05600c0a1000b0038bebbd8548so3160450wmp.3 for ; Wed, 06 Apr 2022 09:06:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gnVQUL3ppm1TNC7utGALyGd2EAWXx63qYM1Qkn/cJqo=; b=CSFm+uVx2yTrQFKqaaNcqReVLFt+1n96DFuNm01EhSjlpgomzC9HLkrsCeHuNckVRU ivsbkDBOTL9/jbQOIzIzUJF4beFjyeR9ZNMEx3MHbWnhIzS8+uJFGvzLGskVySZNjnhL 5opXeKRrabaBG3xcYPBjg+OHMvmnDKpBQCvd3zAt3UEpSW1S421xqQ/b9sSjXH77E931 jGj6i5ArJv2GxMdihxk7CvhdiAWDOjgrIiRp4yR2xgTRv5HTVWD5Avuz11Nq0k66GcCV 42f9QlMAv5ZkUbbv8nIgL+BCXMgdCFlXr9QuWbuzoX+LNlzTYAI49vzPe98Ou1sy98Tv 2KWw== X-Gm-Message-State: AOAM531eIS+6QzzcVogWT1jP04T1Myfj+moYCPj0M6uD46JgO1kW7GSe qzxbBJofIxGmELtpuLaT++tU2s6PYZ+8COC2wwo5IQ4eXXbAiVy1eltigmOjNxUYB5TgDC5ckHM sKbWcN7YnLPHUyvqa/gEjRlJ+AMiTGl4cNibtws1YmmLd3gx6w3TutJHOu6wbQSDh4nEnJsJCf9 0= X-Received: by 2002:a5d:6152:0:b0:205:bcf3:2cc with SMTP id y18-20020a5d6152000000b00205bcf302ccmr7424210wrt.158.1649261205826; Wed, 06 Apr 2022 09:06:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP58khqgo3xreoQlsQ9J6H4ICR/oggJkDwVoOSBbhaMF0ILCTdOLy/FcqT9y3kQS3YNkwSwQ== X-Received: by 2002:a5d:6152:0:b0:205:bcf3:2cc with SMTP id y18-20020a5d6152000000b00205bcf302ccmr7424188wrt.158.1649261205542; Wed, 06 Apr 2022 09:06:45 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f1-20020a1c6a01000000b0038c9f6a3634sm5038899wmc.7.2022.04.06.09.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:06:45 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Thomas Zimmermann , Daniel Vetter , Javier Martinez Canillas , Borislav Petkov , Greg Kroah-Hartman Subject: [RFC PATCH 2/5] firmware: sysfb: Add helpers to unregister a pdev and disable registration Date: Wed, 6 Apr 2022 18:06:29 +0200 Message-Id: <20220406160632.496684-3-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406160632.496684-1-javierm@redhat.com> References: <20220406160632.496684-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These can be used by subsystems to unregister a platform device registered by sysfb and also to disable future platform device registration in sysfb. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas --- drivers/firmware/sysfb.c | 47 +++++++++++++++++++++++++++++++++++----- include/linux/sysfb.h | 19 ++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/sysfb.c b/drivers/firmware/sysfb.c index b032f40a92de..08ae78c083f1 100644 --- a/drivers/firmware/sysfb.c +++ b/drivers/firmware/sysfb.c @@ -34,21 +34,52 @@ #include #include =20 +static struct platform_device *pd; +static DEFINE_MUTEX(load_lock); +static bool disabled; + +void sysfb_disable(void) +{ + mutex_lock(&load_lock); + disabled =3D true; + mutex_unlock(&load_lock); +} +EXPORT_SYMBOL_GPL(sysfb_disable); + +bool sysfb_try_unregister(struct device *dev) +{ + bool ret =3D true; + + mutex_lock(&load_lock); + if (!pd || pd !=3D to_platform_device(dev)) + return false; + + platform_device_unregister(to_platform_device(dev)); + pd =3D NULL; + mutex_unlock(&load_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(sysfb_try_unregister); + static __init int sysfb_init(void) { struct screen_info *si =3D &screen_info; struct simplefb_platform_data mode; - struct platform_device *pd; const char *name; bool compatible; - int ret; + int ret =3D 0; + + mutex_lock(&load_lock); + if (disabled) + goto unlock_mutex; =20 /* try to create a simple-framebuffer device */ compatible =3D sysfb_parse_mode(si, &mode); if (compatible) { pd =3D sysfb_create_simplefb(si, &mode); if (!IS_ERR(pd)) - return 0; + goto unlock_mutex; } =20 /* if the FB is incompatible, create a legacy framebuffer device */ @@ -60,8 +91,10 @@ static __init int sysfb_init(void) name =3D "platform-framebuffer"; =20 pd =3D platform_device_alloc(name, 0); - if (!pd) - return -ENOMEM; + if (!pd) { + ret =3D -ENOMEM; + goto unlock_mutex; + } =20 sysfb_apply_efi_quirks(pd); =20 @@ -73,9 +106,11 @@ static __init int sysfb_init(void) if (ret) goto err; =20 - return 0; + goto unlock_mutex; err: platform_device_put(pd); +unlock_mutex: + mutex_unlock(&load_lock); return ret; } =20 diff --git a/include/linux/sysfb.h b/include/linux/sysfb.h index 9857518f4cdd..2bbc0ed9b0dd 100644 --- a/include/linux/sysfb.h +++ b/include/linux/sysfb.h @@ -55,6 +55,25 @@ struct efifb_dmi_info { int flags; }; =20 +#ifdef CONFIG_SYSFB + +void sysfb_disable(void); +bool sysfb_try_unregister(struct device *dev); + +#else /* CONFIG_SYSFB */ + +void sysfb_disable(void) +{ + +} + +bool sysfb_try_unregister(struct device *dev) +{ + return false; +} + +#endif /* CONFIG_SYSFB */ + #ifdef CONFIG_EFI =20 extern struct efifb_dmi_info efifb_dmi_list[]; --=20 2.35.1 From nobody Fri Jun 19 07:17:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FA53C433EF for ; Wed, 6 Apr 2022 17:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239778AbiDFR5f (ORCPT ); Wed, 6 Apr 2022 13:57:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239491AbiDFR5G (ORCPT ); Wed, 6 Apr 2022 13:57:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F31DD197522 for ; Wed, 6 Apr 2022 09:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649261210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KV4A7vxPY5Ri/A7ExTRv30H1oUVvMjyO4SRhZ4A4Rkc=; b=NxE4X8f5I1DdqXKzABMRyFx0T97MPrGcEjV+ssrEDUZOlhkMoTixAUm6bNnU0mhLap032t pVtzDQFv/iYmlCsMlY3lr3CX1KJFWgh8pP+RhD0u6oKQ27YUzp1HZHztqBnWcT6k30Mk/Y LeWKs2c+uhaEOTkZULTVp1b9KwTnn+w= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-73-5bnbo2WgM5CLfP0kJvIA7w-1; Wed, 06 Apr 2022 12:06:49 -0400 X-MC-Unique: 5bnbo2WgM5CLfP0kJvIA7w-1 Received: by mail-wm1-f71.google.com with SMTP id c125-20020a1c3583000000b0038e3f6e871aso779342wma.8 for ; Wed, 06 Apr 2022 09:06:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KV4A7vxPY5Ri/A7ExTRv30H1oUVvMjyO4SRhZ4A4Rkc=; b=GVShr2X9GQbH7H6Gp2bNAnjb/u1M4EjXuWRCW4m8P19jsV4AEdP1fWcJDXyBacgB9Y 1KZ0BEGv/h2t1NUrb1XBUNl42SGT8wX17IOI3QftfI8l4F21rtaNrBzNwN7kA4iP0nmj FR1r/eaMNZuXQ4/otoma3XxelzW8ODemX748mRTKnhtgfYXB2NtA/EODQ5Vx5jbLfssD 2uxypQDGRISPcPESzI3Lhvi91C1dRRDt5RAg0n8RZS/QE5lM2ZLfxXQzDpIebNeMvwAY WBvqGM3baTOB/DYv/U8+cNPc6yvdG/FUwRklmnQPX05b0PhlpP379UL1B+x17HK7B7yY NY/g== X-Gm-Message-State: AOAM530X+k5UCLfTqJWM7Zsbz7XawT1G2ChjIRVS9xXPvTYb/xHZynwx B0GdI0vppFShQx7FnqGta7a2wj5y7jqaCHuNVXy309wmrHpmyc1ZBUc5XKmePhyQxTUq9xEqkpk nEMcZFks8DUocp+dTfDhtNhVpJFtQxZwGYSnrjOXjcGn77XFt6TiDJt2QF5H/9O8wdrM+BMklkA c= X-Received: by 2002:adf:f94d:0:b0:1e5:5ca1:2b80 with SMTP id q13-20020adff94d000000b001e55ca12b80mr7358644wrr.323.1649261207595; Wed, 06 Apr 2022 09:06:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4iqTGXWAmr0kVXiSaBoH7zqLfupO6IvuwBcok5RYqdCJJH/FQ8YSgWM4GphZdzl59KrH3Wg== X-Received: by 2002:adf:f94d:0:b0:1e5:5ca1:2b80 with SMTP id q13-20020adff94d000000b001e55ca12b80mr7358600wrr.323.1649261207193; Wed, 06 Apr 2022 09:06:47 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f1-20020a1c6a01000000b0038c9f6a3634sm5038899wmc.7.2022.04.06.09.06.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:06:46 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Thomas Zimmermann , Daniel Vetter , Javier Martinez Canillas , Alex Deucher , Guenter Roeck , Helge Deller , Sam Ravnborg , Xiyu Yang , Zhen Lei , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Subject: [RFC PATCH 3/5] fbdev: Restart conflicting fb removal loop when unregistering devices Date: Wed, 6 Apr 2022 18:06:30 +0200 Message-Id: <20220406160632.496684-4-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406160632.496684-1-javierm@redhat.com> References: <20220406160632.496684-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Drivers that want to remove registered conflicting framebuffers prior to register their own framebuffer, calls remove_conflicting_framebuffers(). This function takes the registration_lock mutex, to prevent a races when drivers register framebuffer devices. But if a conflicting framebuffer device is found, the underlaying platform device is unregistered and this will lead to the platform driver .remove callback to be called, which in turn will call to the unregister_framebuffer() that takes the same lock. To prevent this, a struct fb_info.forced_out field was used as indication to unregister_framebuffer() whether the mutex has to be grabbed or not. A cleaner solution is to drop the lock before platform_device_unregister() so unregister_framebuffer() can take it when called from the fbdev driver, and just grab the lock again after the device has been registered and do a removal loop restart. Since the framebuffer devices will already be removed, the loop would just finish when no more conflicting framebuffers are found. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas --- drivers/video/fbdev/core/fbmem.c | 21 ++++++++++++++------- include/linux/fb.h | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index b585339509b0..c1bfb8df9cba 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1555,6 +1555,7 @@ static void do_remove_conflicting_framebuffers(struct= apertures_struct *a, { int i; =20 +restart_removal: /* check all firmware fbs and kick off if the base addr overlaps */ for_each_registered_fb(i) { struct apertures_struct *gen_aper; @@ -1582,8 +1583,18 @@ static void do_remove_conflicting_framebuffers(struc= t apertures_struct *a, * fix would add code to remove the device from the system. */ if (dev_is_platform(device)) { - registered_fb[i]->forced_out =3D true; + /* + * Drop the lock since the driver will call to the + * unregister_framebuffer() function that takes it. + */ + mutex_unlock(®istration_lock); platform_device_unregister(to_platform_device(device)); + mutex_lock(®istration_lock); + /* + * Restart the removal now that the platform device + * has been unregistered and its associated fb gone. + */ + goto restart_removal; } else { pr_warn("fb%d: cannot remove device\n", i); do_unregister_framebuffer(registered_fb[i]); @@ -1917,13 +1928,9 @@ EXPORT_SYMBOL(register_framebuffer); void unregister_framebuffer(struct fb_info *fb_info) { - bool forced_out =3D fb_info->forced_out; - - if (!forced_out) - mutex_lock(®istration_lock); + mutex_lock(®istration_lock); do_unregister_framebuffer(fb_info); - if (!forced_out) - mutex_unlock(®istration_lock); + mutex_unlock(®istration_lock); } EXPORT_SYMBOL(unregister_framebuffer); =20 diff --git a/include/linux/fb.h b/include/linux/fb.h index 39baa9a70779..f1e0cd751b06 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -503,7 +503,6 @@ struct fb_info { } *apertures; =20 bool skip_vt_switch; /* no VT switch on suspend/resume required */ - bool forced_out; /* set when being removed by another driver */ }; =20 static inline struct apertures_struct *alloc_apertures(unsigned int max_nu= m) { --=20 2.35.1 From nobody Fri Jun 19 07:17:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C315C433EF for ; Wed, 6 Apr 2022 17:56:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239992AbiDFR5o (ORCPT ); Wed, 6 Apr 2022 13:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239693AbiDFR5F (ORCPT ); Wed, 6 Apr 2022 13:57:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1DD641A771E for ; Wed, 6 Apr 2022 09:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649261211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U2QzSBkwn7Yafa/16sbGGbBUM4FbySeU5GGeHJm/Jx0=; b=env1f3IYLBLUN0bDvO5fF8B61UkIhGpjGygidOmSM6sNxq2RRqUQk+b68iXXTSj+PrM2/k 2MtvZZsFpN9JPSFJ1ntmxscdtgciLV6J5p6g7Yrv/z+9R/fDWeJuxc1hQKjCEvvhkRmNRn H5eZjl4EoDk/wgCQafJPX5DP5sAAZ5k= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-12-l_pP4vIKNVOfLT1dI12TEQ-1; Wed, 06 Apr 2022 12:06:50 -0400 X-MC-Unique: l_pP4vIKNVOfLT1dI12TEQ-1 Received: by mail-wm1-f72.google.com with SMTP id x8-20020a7bc768000000b0038e73173886so1513826wmk.6 for ; Wed, 06 Apr 2022 09:06:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U2QzSBkwn7Yafa/16sbGGbBUM4FbySeU5GGeHJm/Jx0=; b=2PPqW6vIRgiq9mbuj3sIoRDtAlTyLOF6YXX7RXtCNOJi+dtUgwp5yvC0dZlK8bDLN5 kOf8UT0gqmEw86AntuLOJ3pZ/bUob0+AjwWqE8SMzJtKFHBO9+zVSfB8ZHi8y0bZcJH0 Q0LykdKqt2Tmn8Doj21VFZ26jy1Aug9rPyFweHXKfiv586P0iPqoDJeTYVlIYMoUOwsm ZPPCjSr4q0h4i9hbCabzO8fNolrerwazY3clwSJJR4R+twaKy9oaeXPF3qW9Z8FoPhm0 MX2znxhmxIjJRzIqgH4useh38gb3dV3g8sOSiHOXTN6Mj4Xmmyg4vI6bTAL1WaVhXvU5 erVA== X-Gm-Message-State: AOAM533PESef2Z8vZhno9DV97xVnbF5F0RzcJj2YhhAYV2AELR+CVyxM vhNemvABmA2SZnXMY618kYcjoZ5eXnho8qLZuHJ+A3e83/cCUSsTmcYtfcuTenmzCbzRNSHqd+O qCbibKsw3hKvhQgrh33/rHUzKZx7gLwK5qb5A+dmi171AbIRsklzWcKB11PrqJ7JhweVdO5uGc2 M= X-Received: by 2002:a05:600c:3b26:b0:38c:8358:4b84 with SMTP id m38-20020a05600c3b2600b0038c83584b84mr8262645wms.185.1649261208783; Wed, 06 Apr 2022 09:06:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrWRPcdVNxxa0OQoFxVtMgEvN6P53Xni3VcPZinWUwk/8XrPqG2DL56DBxegaE9MICKK7T2Q== X-Received: by 2002:a05:600c:3b26:b0:38c:8358:4b84 with SMTP id m38-20020a05600c3b2600b0038c83584b84mr8262596wms.185.1649261208370; Wed, 06 Apr 2022 09:06:48 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f1-20020a1c6a01000000b0038c9f6a3634sm5038899wmc.7.2022.04.06.09.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:06:48 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Thomas Zimmermann , Daniel Vetter , Javier Martinez Canillas , Alex Deucher , Hans de Goede , Helge Deller , Sam Ravnborg , Xiyu Yang , Zhen Lei , Zheyu Ma , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Subject: [RFC PATCH 4/5] fbdev: Fix some race conditions between fbmem and sysfb Date: Wed, 6 Apr 2022 18:06:31 +0200 Message-Id: <20220406160632.496684-5-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406160632.496684-1-javierm@redhat.com> References: <20220406160632.496684-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The platform devices registered in sysfb match with a firmware-based fbdev or DRM driver, that are used to have early graphics using framebuffers set up by the system firmware. Real DRM drivers later are probed and remove all conflicting framebuffers, leading to these platform devices for generic drivers to be unregistered. But the current solution has two issues that this patch fixes: 1) It is a layering violation for the fbdev core to unregister a device that was registered by sysfb. Instead, the sysfb_try_unregister() helper function can be called for sysfb to attempt unregistering the device if is the one registered. 2) The sysfb_init() function could be called after a DRM driver is probed and requested to unregister devices for drivers with a conflicting fb. To prevent this, disable any future sysfb platform device registration by calling sysfb_disable(), if a driver requested to remove conflicting framebuffers with remove_conflicting_framebuffers(). Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas --- drivers/video/fbdev/core/fbmem.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index c1bfb8df9cba..acf641b05d11 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1588,7 +1589,10 @@ static void do_remove_conflicting_framebuffers(struc= t apertures_struct *a, * unregister_framebuffer() function that takes it. */ mutex_unlock(®istration_lock); - platform_device_unregister(to_platform_device(device)); + if (!sysfb_try_unregister(device)) { + /* sysfb didn't register this device, unregister it */ + platform_device_unregister(to_platform_device(device)); + } mutex_lock(®istration_lock); /* * Restart the removal now that the platform device @@ -1781,6 +1785,17 @@ int remove_conflicting_framebuffers(struct apertures= _struct *a, do_free =3D true; } =20 + /* + * If a driver asked to unregister a platform device registered by + * sysfb, then can be assumed that this is a driver for a display + * that is set up by the system firmware and has a generic driver. + * + * Drivers for devices that don't have a generic driver will never + * ask for this, so let's assume that a real driver for the display + * was already probed and prevent sysfb to register devices later. + */ + sysfb_disable(); + mutex_lock(®istration_lock); do_remove_conflicting_framebuffers(a, name, primary); mutex_unlock(®istration_lock); --=20 2.35.1 From nobody Fri Jun 19 07:17:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD193C433FE for ; Wed, 6 Apr 2022 17:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239654AbiDFR6C (ORCPT ); Wed, 6 Apr 2022 13:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239711AbiDFR5J (ORCPT ); Wed, 6 Apr 2022 13:57:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 36AF9C31C3 for ; Wed, 6 Apr 2022 09:06:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649261212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4FhXBUnLq/AeYpcQ43hIiOOWtFlBWzfoVNvi0Bsh0Mg=; b=Bj7jYjRTgA27PWqK4phuuDKm0/fOdZmtyPdtONAVvAE/B7at75HMgS7yeLEwoLZlxyy6mC oycH+2iEoxdVTbcFQ9THAFoqLm6or6Fu9p2bpiHLsRIq++NIS/fgIGy/2tiCjs10j4cPQ7 ENdDKaoNJPhEceKi7vOxQBMYE4WZe2I= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583--lmWiG-UNke42XNIkdXcfg-1; Wed, 06 Apr 2022 12:06:51 -0400 X-MC-Unique: -lmWiG-UNke42XNIkdXcfg-1 Received: by mail-wr1-f70.google.com with SMTP id x17-20020adfbb51000000b002060ff71a3bso652534wrg.22 for ; Wed, 06 Apr 2022 09:06:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4FhXBUnLq/AeYpcQ43hIiOOWtFlBWzfoVNvi0Bsh0Mg=; b=QmVUTOvidpEYk+3vcCPTJgg7uGbUAcW6OO/p6DVhzrKlxIN9ek/8FmX7F/V8+YNO4/ kHOhg53wOZbkRZZtXCTXrS3TkKlyz8Qwvob4bekWO96Tb3OF4UCopHQE8WB6E88wxpim C5znNavIapcWYVKvtEheYjrsWIKOaqz6WJsSV970Ca4cLRI8iWTFv1L2e0F3FmvVOfds EREGMPtYfmzP6pHKhh3DUN5AqwM14ZtOFZOmjaLDKGM4kxg5/B3FfiruEelPrQaQzTjh iA97+HVRqI8C8Oo9e7C+PeSVHOTwB8IipQp7NMHqR+7ng2zxQsZtedUffXh08XsNW4df R8hA== X-Gm-Message-State: AOAM533kB9r0BZzIQOdpyKkHV0/ScneJECWCOrvgjjxlgQ33qaZtsAsj 0gj6HHJmVmUGT5Csod479WCnk6P0ir5ZzvrUyKRRBpwFeR5w6Wib/P4RZG6OOTEXg8AvGwATqS7 tyUowSdpcwP+TPsfYKnqvWA2e0KIoLgmpr9NabO5+bL5sBIODk8z0DUG0T81c9CWhHqUVJfSSnY g= X-Received: by 2002:adf:dd4d:0:b0:203:f178:b78b with SMTP id u13-20020adfdd4d000000b00203f178b78bmr7137246wrm.93.1649261209890; Wed, 06 Apr 2022 09:06:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjTyMg4XL89qFWV3gB2V/HQc1uQjBder3TeH9rKQDOsGox6TANK3aF+8wdzRe76EhPl9Zl5g== X-Received: by 2002:adf:dd4d:0:b0:203:f178:b78b with SMTP id u13-20020adfdd4d000000b00203f178b78bmr7137221wrm.93.1649261209641; Wed, 06 Apr 2022 09:06:49 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f1-20020a1c6a01000000b0038c9f6a3634sm5038899wmc.7.2022.04.06.09.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:06:49 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Thomas Zimmermann , Daniel Vetter , Zack Rusin , Javier Martinez Canillas , Hans de Goede , Ilya Trukhanov , Daniel Vetter , Peter Jones , linux-fbdev@vger.kernel.org, Helge Deller , dri-devel@lists.freedesktop.org Subject: [RFC PATCH 5/5] Revert "fbdev: Prevent probing generic drivers if a FB is already registered" Date: Wed, 6 Apr 2022 18:06:32 +0200 Message-Id: <20220406160632.496684-6-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406160632.496684-1-javierm@redhat.com> References: <20220406160632.496684-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniel Vetter This reverts commit fb561bf9abde49f7e00fdbf9ed2ccf2d86cac8ee. With commit 27599aacbaefcbf2af7b06b0029459bbf682000d Author: Thomas Zimmermann Date: Tue Jan 25 10:12:18 2022 +0100 fbdev: Hot-unplug firmware fb devices on forced removal this should be fixed properly and we can remove this somewhat hackish check here (e.g. this won't catch drm drivers if fbdev emulation isn't enabled). Cc: Thomas Zimmermann Cc: Zack Rusin Cc: Javier Martinez Canillas Cc: Zack Rusin Cc: Hans de Goede Cc: Ilya Trukhanov Signed-off-by: Daniel Vetter Cc: Peter Jones Cc: linux-fbdev@vger.kernel.org Signed-off-by: Javier Martinez Canillas --- drivers/video/fbdev/efifb.c | 11 ----------- drivers/video/fbdev/simplefb.c | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index ea42ba6445b2..edca3703b964 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -351,17 +351,6 @@ static int efifb_probe(struct platform_device *dev) char *option =3D NULL; efi_memory_desc_t md; =20 - /* - * Generic drivers must not be registered if a framebuffer exists. - * If a native driver was probed, the display hardware was already - * taken and attempting to use the system framebuffer is dangerous. - */ - if (num_registered_fb > 0) { - dev_err(&dev->dev, - "efifb: a framebuffer is already registered\n"); - return -EINVAL; - } - if (screen_info.orig_video_isVGA !=3D VIDEO_TYPE_EFI || pci_dev_disabled) return -ENODEV; =20 diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 94fc9c6d0411..0ef41173325a 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -413,17 +413,6 @@ static int simplefb_probe(struct platform_device *pdev) struct simplefb_par *par; struct resource *res, *mem; =20 - /* - * Generic drivers must not be registered if a framebuffer exists. - * If a native driver was probed, the display hardware was already - * taken and attempting to use the system framebuffer is dangerous. - */ - if (num_registered_fb > 0) { - dev_err(&pdev->dev, - "simplefb: a framebuffer is already registered\n"); - return -EINVAL; - } - if (fb_get_options("simplefb", NULL)) return -ENODEV; =20 --=20 2.35.1