From nobody Sun Jun 28 10:36:33 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 5BC4DC433FE for ; Tue, 8 Feb 2022 22:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386300AbiBHWWr (ORCPT ); Tue, 8 Feb 2022 17:22:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386693AbiBHVIc (ORCPT ); Tue, 8 Feb 2022 16:08:32 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D95C0612BD for ; Tue, 8 Feb 2022 13:08:31 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id r7so137850wmq.5 for ; Tue, 08 Feb 2022 13:08:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1IuiSyqatCt+l1wk5WgkOInkMrehuaZuz9Mxu04TsqY=; b=avHkOSu+x6pfmx4+fLtEewoBxnRMkJmK8t/rEpPIL34bWtfdlDa2+3sCJJZi5z4PuV ckFrSEhaJ0yEOaXqGl9xGK8CTEVT5ZIucUpSjA4gWTpu5UtAWEHI7DaOygEQd+miUzVZ fXH6kBN8oggwje5UwlVqhRF2IcoTAxLW3cqWs= 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=1IuiSyqatCt+l1wk5WgkOInkMrehuaZuz9Mxu04TsqY=; b=xPI02SMXHfUqOVIPCBkmkUycUfHoThxV88MbNC5b9Zze89lf5IbgbqfkmbWlzeQN9G 4gLqL+lOrp1Z1+xZvZhp+/tbZZnajNGAqLJIO/4qlZ1oe9BAuFP81+5/WcoL3LEvkRW8 QFuzTUU+0+GRLTk6HTh3gL3cWRNcMF4A/Ungg8Pcw9VQ01mTRlQv/1jZZAVPtBzXT45G pU7EMVWh2+ySmjpUXVLgvxY0EtnAcw0Q/YWj+nOKuNiT5IhaMDm7/zYjcN3MrZ4sHv69 MJerUdJUkoCppftfUzGES+4UJzk++zp/x2/RGyEkjsuHoAFBqOIxZ1VEXz7wVpRhG1Iy TmIA== X-Gm-Message-State: AOAM531Mc+rpcErlt6eJQsdDHjfGZAKrvimaTeuk9Zh4hkqKnDvF5rYS MatuIBur0fRMRQsm3W0Y8NfAXQ== X-Google-Smtp-Source: ABdhPJyUoNAHSJRgncTABvPUK493XLqXy+tMNLIpUB+u6ODVBYoOWnDUowuWpfEK97CmfZnMhYogLg== X-Received: by 2002:a1c:7915:: with SMTP id l21mr2580207wme.154.1644354510218; Tue, 08 Feb 2022 13:08:30 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:29 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Geert Uytterhoeven , Daniel Vetter , Helge Deller , Daniel Vetter , Thomas Zimmermann , Du Cheng , Tetsuo Handa , Claudio Suarez , Greg Kroah-Hartman Subject: [PATCH v2 01/19] fbcon: delete a few unneeded forward decl Date: Tue, 8 Feb 2022 22:08:06 +0100 Message-Id: <20220208210824.2238981-2-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" I didn't bother with any code movement to fix the others, these just got a bit in the way. v2: Rebase on top of Helge's reverts. Acked-by: Sam Ravnborg (v1) Reviewed-by: Geert Uytterhoeven (v1) Signed-off-by: Daniel Vetter Cc: Helge Deller Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Du Cheng Cc: Tetsuo Handa Cc: Claudio Suarez Cc: Greg Kroah-Hartman Acked-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 2fc1b80a26ad..235eaab37d84 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -163,29 +163,14 @@ static int fbcon_cursor_noblink; * Interface used by the world */ =20 -static const char *fbcon_startup(void); -static void fbcon_init(struct vc_data *vc, int init); -static void fbcon_deinit(struct vc_data *vc); -static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, - int width); -static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos); -static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, - int count, int ypos, int xpos); static void fbcon_clear_margins(struct vc_data *vc, int bottom_only); -static void fbcon_cursor(struct vc_data *vc, int mode); static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, int height, int width); -static int fbcon_switch(struct vc_data *vc); -static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch); static void fbcon_set_palette(struct vc_data *vc, const unsigned char *tab= le); =20 /* * Internal routines */ -static __inline__ void ywrap_up(struct vc_data *vc, int count); -static __inline__ void ywrap_down(struct vc_data *vc, int count); -static __inline__ void ypan_up(struct vc_data *vc, int count); -static __inline__ void ypan_down(struct vc_data *vc, int count); static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, i= nt sy, int sx, int dy, int dx, int height, int width, u_int y_break); static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo = *var, @@ -194,8 +179,8 @@ static void fbcon_redraw_move(struct vc_data *vc, struc= t fbcon_display *p, int line, int count, int dy); static void fbcon_modechanged(struct fb_info *info); static void fbcon_set_all_vcs(struct fb_info *info); -static void fbcon_start(void); static void fbcon_exit(void); + static struct device *fbcon_device; =20 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 D1D34C47080 for ; Tue, 8 Feb 2022 22:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387642AbiBHWZ5 (ORCPT ); Tue, 8 Feb 2022 17:25:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386694AbiBHVIe (ORCPT ); Tue, 8 Feb 2022 16:08:34 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4E47C0612BA for ; Tue, 8 Feb 2022 13:08:32 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id k18so527901wrg.11 for ; Tue, 08 Feb 2022 13:08:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gIPhliOnck3yOxw+Dv+3394kB7U1re82IdjUQLdsD7g=; b=Z8I9ZWk9KMGjtYjkOSq4opEZfrkrnm27stq7L+c8hIZk05qksyUdm4+sUlt0rBndyT DQX+SOTc8GS9LeEBc6pi7uSkAVol2kWAn54PJoRSgOd/ccDFsbs79VlWsrIJgy+5UY4z adq/p7y0DkEQ++cwOVxs6Wiyy9rvfDf9eMg00= 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=gIPhliOnck3yOxw+Dv+3394kB7U1re82IdjUQLdsD7g=; b=ZslNGvtnLcRP5n3jMG00HbyWfNwfF+QuowoEnP0twf4//lUUlnQhPL57AIRQGs8lXz sr7BVdsAWf8VGJfg1v7TQM/D5w9J5FYfRJNXB87xJmlkcDSQgXQ9sMAkCkRI1+Ux63ft KCZmgPdl21yCeG0WRuymFjMQE86aWeXYnxvF94Ymbxw6kcS8NhkxRlU9jTJKEcvc4gz4 g6FFi2CYl4SdfqF6XcmtBUrVVKC0JIrcRJN3PggPK8ESeGXtffdob2dGEhPKk/wJtllt d1+bbUojoJ7AwZ5bIMd55CAy4t4+CYwyFBwEsrW4gx4jnNel9/De3mhPLQ3/+HE83lzQ gpmw== X-Gm-Message-State: AOAM532jghWfwzQeqIyLmcICG1uTwtk/1vu6DxWS53X13h0dg+2Pb0NI VWxmj74AKlQ6mtpLhfJAxtyULg== X-Google-Smtp-Source: ABdhPJyfRPn4N3kWII/WebNvQR+2lSObKOj91UPPo9uSAdMr7ixXbhsF1UhRz3GGz4BQn3bFDSUu7A== X-Received: by 2002:a5d:64c1:: with SMTP id f1mr4878344wri.5.1644354511285; Tue, 08 Feb 2022 13:08:31 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:30 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Daniel Vetter , Helge Deller , Daniel Vetter , Thomas Zimmermann , Du Cheng , Tetsuo Handa , Claudio Suarez , Greg Kroah-Hartman Subject: [PATCH v2 02/19] fbcon: Move fbcon_bmove(_rec) functions Date: Tue, 8 Feb 2022 22:08:07 +0100 Message-Id: <20220208210824.2238981-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Avoids two forward declarations, and more importantly, matches what I've done in my fbcon scrolling restore patches - so I need this to avoid a bunch of conflicts in rebasing since we ended up merging Helge's series instead. Signed-off-by: Daniel Vetter Cc: Helge Deller Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Du Cheng Cc: Tetsuo Handa Cc: Claudio Suarez Cc: Greg Kroah-Hartman Acked-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas --- drivers/video/fbdev/core/fbcon.c | 134 +++++++++++++++---------------- 1 file changed, 65 insertions(+), 69 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 235eaab37d84..e925bb608e25 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -164,15 +164,11 @@ static int fbcon_cursor_noblink; */ =20 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only); -static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, - int height, int width); static void fbcon_set_palette(struct vc_data *vc, const unsigned char *tab= le); =20 /* * Internal routines */ -static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, i= nt sy, int sx, - int dy, int dx, int height, int width, u_int y_break); static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo = *var, int unit); static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p, @@ -1667,6 +1663,71 @@ static void fbcon_redraw(struct vc_data *vc, struct = fbcon_display *p, } } =20 +static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, i= nt sy, int sx, + int dy, int dx, int height, int width, u_int y_break) +{ + struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops =3D info->fbcon_par; + u_int b; + + if (sy < y_break && sy + height > y_break) { + b =3D y_break - sy; + if (dy < sy) { /* Avoid trashing self */ + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + } else { + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + } + return; + } + + if (dy < y_break && dy + height > y_break) { + b =3D y_break - dy; + if (dy < sy) { /* Avoid trashing self */ + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + } else { + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + } + return; + } + ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx, + height, width); +} + +static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, + int height, int width) +{ + struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_display *p =3D &fb_display[vc->vc_num]; + + if (fbcon_is_inactive(vc, info)) + return; + + if (!width || !height) + return; + + /* Split blits that cross physical y_wrap case. + * Pathological case involves 4 blits, better to use recursive + * code rather than unrolled case + * + * Recursive invocations don't need to erase the cursor over and + * over again, so we use fbcon_bmove_rec() + */ + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width, + p->vrows - p->yscroll); +} + static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int = b, enum con_scroll dir, unsigned int count) { @@ -1867,71 +1928,6 @@ static bool fbcon_scroll(struct vc_data *vc, unsigne= d int t, unsigned int b, } =20 =20 -static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, - int height, int width) -{ - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; - struct fbcon_display *p =3D &fb_display[vc->vc_num]; - - if (fbcon_is_inactive(vc, info)) - return; - - if (!width || !height) - return; - - /* Split blits that cross physical y_wrap case. - * Pathological case involves 4 blits, better to use recursive - * code rather than unrolled case - * - * Recursive invocations don't need to erase the cursor over and - * over again, so we use fbcon_bmove_rec() - */ - fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width, - p->vrows - p->yscroll); -} - -static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, i= nt sy, int sx, - int dy, int dx, int height, int width, u_int y_break) -{ - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; - struct fbcon_ops *ops =3D info->fbcon_par; - u_int b; - - if (sy < y_break && sy + height > y_break) { - b =3D y_break - sy; - if (dy < sy) { /* Avoid trashing self */ - fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, - y_break); - fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, - height - b, width, y_break); - } else { - fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, - height - b, width, y_break); - fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, - y_break); - } - return; - } - - if (dy < y_break && dy + height > y_break) { - b =3D y_break - dy; - if (dy < sy) { /* Avoid trashing self */ - fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, - y_break); - fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, - height - b, width, y_break); - } else { - fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, - height - b, width, y_break); - fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, - y_break); - } - return; - } - ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx, - height, width); -} - static void updatescrollmode_accel(struct fbcon_display *p, struct fb_info *info, struct vc_data *vc) --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 4194EC433F5 for ; Tue, 8 Feb 2022 22:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387855AbiBHWby (ORCPT ); Tue, 8 Feb 2022 17:31:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386699AbiBHVIg (ORCPT ); Tue, 8 Feb 2022 16:08:36 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 654EAC0612BE for ; Tue, 8 Feb 2022 13:08:35 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id l67-20020a1c2546000000b00353951c3f62so153508wml.5 for ; Tue, 08 Feb 2022 13:08:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a5WrS/1rmXvD/BYbGf8gVLMNVbqD+GkBVWeKUPnYEUE=; b=W8SZ9ZT9lnqf674qYwX61QIIXfYPpz5TT8FNFquYqMWF60Zr1NxVSo67LFUIumhY/b g4X3DWnYQ4E9O0TT9I27jrKoBmg4rpZuW34qAkgkfckRl0rxiOId6Jms4FaL+TttstLl RZw/gE3MZ7mAZ0AStwQU91DCKbDEAy83Zt1DU= 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=a5WrS/1rmXvD/BYbGf8gVLMNVbqD+GkBVWeKUPnYEUE=; b=UtQBa8h1at7l9jWbsrqc7CYjlEb0DQyvpSRB5heVOK04Ja0ni+6DnwCAMGMOs/ZnSd i3Ez20sNwvdMDP0vqadOMXCplEmMogRUHOdcJU0rXzLFY1WAaq7r4wzCpuIBMW/ysGNG 0AfopRfhJp3LnwtcwoH71wz3dI/HzOEQrn1HySUz2Xaraxs8h06NN6M+M17k55aj+s7w 6FFzQDQq+MwAV3NYScLY07iy1UxHNf1Evup7CF+b8g94mmfWj+DSARUhVzNUuhkDHkKA KJ19izyUWdKot4nbBRjDkle4KCCWTCOYRYLzF1mjAs90Kx/K9jH6j9dx4xHvHlyOQmi+ tkNw== X-Gm-Message-State: AOAM531y9zTJnxxPM+RIuCQ5k6t2BkfjSvduLmGZLqJKe/BI/138vdun EEMlrNJgTXPXxfAwolxy/ks1sg== X-Google-Smtp-Source: ABdhPJymquC64RJAFkzllw/eFz8WLOUKu7ZMOr++7kAYlKbVxvjPxIJXICIuvaEML/N2TifrI9Fp2w== X-Received: by 2002:a05:600c:4f85:: with SMTP id n5mr2579212wmq.64.1644354513896; Tue, 08 Feb 2022 13:08:33 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:32 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Helge Deller , Daniel Vetter , Greg Kroah-Hartman , Tetsuo Handa , Du Cheng , Claudio Suarez , Thomas Zimmermann Subject: [PATCH v2 03/19] fbcon: Introduce wrapper for console->fb_info lookup Date: Tue, 8 Feb 2022 22:08:08 +0100 Message-Id: <20220208210824.2238981-4-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Half of it is protected by console_lock, but the other half is a lot more awkward: Registration/deregistration of fbdev are serialized, but we don't really clear out anything in con2fb_map and so there's potential for use-after free mixups. First step is to encapsulate the lookup. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Helge Deller Cc: Daniel Vetter Cc: Greg Kroah-Hartman Cc: Tetsuo Handa Cc: Du Cheng Cc: Claudio Suarez Cc: Thomas Zimmermann Acked-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.c | 76 ++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index e925bb608e25..b75e638cb83d 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -110,6 +110,18 @@ static struct fbcon_display fb_display[MAX_NR_CONSOLES= ]; static signed char con2fb_map[MAX_NR_CONSOLES]; static signed char con2fb_map_boot[MAX_NR_CONSOLES]; =20 +static struct fb_info *fbcon_info_from_console(int console) +{ + WARN_CONSOLE_UNLOCKED(); + + /* + * Note that only con2fb_map is protected by the console lock, + * registered_fb is protected by a separate mutex. This lookup can + * therefore race. + */ + return registered_fb[con2fb_map[console]]; +} + static int logo_lines; /* logo_shown is an index to vc_cons when >=3D 0; otherwise follows FBCON_= LOGO enums. */ @@ -199,7 +211,7 @@ static void fbcon_rotate(struct fb_info *info, u32 rota= te) if (!ops || ops->currcon =3D=3D -1) return; =20 - fb_info =3D registered_fb[con2fb_map[ops->currcon]]; + fb_info =3D fbcon_info_from_console(ops->currcon); =20 if (info =3D=3D fb_info) { struct fbcon_display *p =3D &fb_display[ops->currcon]; @@ -226,7 +238,7 @@ static void fbcon_rotate_all(struct fb_info *info, u32 = rotate) for (i =3D first_fb_vc; i <=3D last_fb_vc; i++) { vc =3D vc_cons[i].d; if (!vc || vc->vc_mode !=3D KD_TEXT || - registered_fb[con2fb_map[i]] !=3D info) + fbcon_info_from_console(i) !=3D info) continue; =20 p =3D &fb_display[vc->vc_num]; @@ -356,7 +368,7 @@ static void fb_flashcursor(struct work_struct *work) vc =3D vc_cons[ops->currcon].d; =20 if (!vc || !con_is_visible(vc) || - registered_fb[con2fb_map[vc->vc_num]] !=3D info || + fbcon_info_from_console(vc->vc_num) !=3D info || vc->vc_deccm !=3D 1) { console_unlock(); return; @@ -791,7 +803,7 @@ static void con2fb_init_display(struct vc_data *vc, str= uct fb_info *info, if (show_logo) { struct vc_data *fg_vc =3D vc_cons[fg_console].d; struct fb_info *fg_info =3D - registered_fb[con2fb_map[fg_console]]; + fbcon_info_from_console(fg_console); =20 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols, fg_vc->vc_rows, fg_vc->vc_cols, @@ -1014,7 +1026,7 @@ static void fbcon_init(struct vc_data *vc, int init) if (con2fb_map[vc->vc_num] =3D=3D -1) con2fb_map[vc->vc_num] =3D info_idx; =20 - info =3D registered_fb[con2fb_map[vc->vc_num]]; + info =3D fbcon_info_from_console(vc->vc_num); =20 if (logo_shown < 0 && console_loglevel <=3D CONSOLE_LOGLEVEL_QUIET) logo_shown =3D FBCON_LOGO_DONTSHOW; @@ -1231,7 +1243,7 @@ static void fbcon_deinit(struct vc_data *vc) static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, int width) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; =20 struct fbcon_display *p =3D &fb_display[vc->vc_num]; @@ -1269,7 +1281,7 @@ static void fbcon_clear(struct vc_data *vc, int sy, i= nt sx, int height, static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, int count, int ypos, int xpos) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_display *p =3D &fb_display[vc->vc_num]; struct fbcon_ops *ops =3D info->fbcon_par; =20 @@ -1289,7 +1301,7 @@ static void fbcon_putc(struct vc_data *vc, int c, int= ypos, int xpos) =20 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; =20 if (!fbcon_is_inactive(vc, info)) @@ -1298,7 +1310,7 @@ static void fbcon_clear_margins(struct vc_data *vc, i= nt bottom_only) =20 static void fbcon_cursor(struct vc_data *vc, int mode) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; int c =3D scr_readw((u16 *) vc->vc_pos); =20 @@ -1392,7 +1404,7 @@ static void fbcon_set_disp(struct fb_info *info, stru= ct fb_var_screeninfo *var, =20 static __inline__ void ywrap_up(struct vc_data *vc, int count) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; struct fbcon_display *p =3D &fb_display[vc->vc_num]; =20 @@ -1411,7 +1423,7 @@ static __inline__ void ywrap_up(struct vc_data *vc, i= nt count) =20 static __inline__ void ywrap_down(struct vc_data *vc, int count) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; struct fbcon_display *p =3D &fb_display[vc->vc_num]; =20 @@ -1430,7 +1442,7 @@ static __inline__ void ywrap_down(struct vc_data *vc,= int count) =20 static __inline__ void ypan_up(struct vc_data *vc, int count) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_display *p =3D &fb_display[vc->vc_num]; struct fbcon_ops *ops =3D info->fbcon_par; =20 @@ -1454,7 +1466,7 @@ static __inline__ void ypan_up(struct vc_data *vc, in= t count) =20 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; struct fbcon_display *p =3D &fb_display[vc->vc_num]; =20 @@ -1478,7 +1490,7 @@ static __inline__ void ypan_up_redraw(struct vc_data = *vc, int t, int count) =20 static __inline__ void ypan_down(struct vc_data *vc, int count) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_display *p =3D &fb_display[vc->vc_num]; struct fbcon_ops *ops =3D info->fbcon_par; =20 @@ -1502,7 +1514,7 @@ static __inline__ void ypan_down(struct vc_data *vc, = int count) =20 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int cou= nt) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; struct fbcon_display *p =3D &fb_display[vc->vc_num]; =20 @@ -1666,7 +1678,7 @@ static void fbcon_redraw(struct vc_data *vc, struct f= bcon_display *p, static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, i= nt sy, int sx, int dy, int dx, int height, int width, u_int y_break) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; u_int b; =20 @@ -1708,7 +1720,7 @@ static void fbcon_bmove_rec(struct vc_data *vc, struc= t fbcon_display *p, int sy, static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, int height, int width) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_display *p =3D &fb_display[vc->vc_num]; =20 if (fbcon_is_inactive(vc, info)) @@ -1731,7 +1743,7 @@ static void fbcon_bmove(struct vc_data *vc, int sy, i= nt sx, int dy, int dx, static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int = b, enum con_scroll dir, unsigned int count) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_display *p =3D &fb_display[vc->vc_num]; int scroll_partial =3D info->flags & FBINFO_PARTIAL_PAN_OK; =20 @@ -1996,7 +2008,7 @@ static void updatescrollmode(struct fbcon_display *p, static int fbcon_resize(struct vc_data *vc, unsigned int width,=20 unsigned int height, unsigned int user) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; struct fbcon_display *p =3D &fb_display[vc->vc_num]; struct fb_var_screeninfo var =3D info->var; @@ -2065,7 +2077,7 @@ static int fbcon_switch(struct vc_data *vc) struct fb_var_screeninfo var; int i, ret, prev_console; =20 - info =3D registered_fb[con2fb_map[vc->vc_num]]; + info =3D fbcon_info_from_console(vc->vc_num); ops =3D info->fbcon_par; =20 if (logo_shown >=3D 0) { @@ -2079,7 +2091,7 @@ static int fbcon_switch(struct vc_data *vc) =20 prev_console =3D ops->currcon; if (prev_console !=3D -1) - old_info =3D registered_fb[con2fb_map[prev_console]]; + old_info =3D fbcon_info_from_console(prev_console); /* * FIXME: If we have multiple fbdev's loaded, we need to * update all info->currcon. Perhaps, we can place this @@ -2202,7 +2214,7 @@ static void fbcon_generic_blank(struct vc_data *vc, s= truct fb_info *info, =20 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; =20 if (mode_switch) { @@ -2244,7 +2256,7 @@ static int fbcon_blank(struct vc_data *vc, int blank,= int mode_switch) =20 static int fbcon_debug_enter(struct vc_data *vc) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; =20 ops->save_graphics =3D ops->graphics; @@ -2257,7 +2269,7 @@ static int fbcon_debug_enter(struct vc_data *vc) =20 static int fbcon_debug_leave(struct vc_data *vc) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; =20 ops->graphics =3D ops->save_graphics; @@ -2393,7 +2405,7 @@ static void set_vc_hi_font(struct vc_data *vc, bool s= et) static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcou= nt, const u8 * data, int userfont) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops =3D info->fbcon_par; struct fbcon_display *p =3D &fb_display[vc->vc_num]; int resize; @@ -2447,7 +2459,7 @@ static int fbcon_do_set_font(struct vc_data *vc, int = w, int h, int charcount, static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned int flags) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); unsigned charcount =3D font->charcount; int w =3D font->width; int h =3D font->height; @@ -2511,7 +2523,7 @@ static int fbcon_set_font(struct vc_data *vc, struct = console_font *font, =20 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *fon= t, char *name) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); const struct font_desc *f; =20 if (!name) @@ -2535,7 +2547,7 @@ static struct fb_cmap palette_cmap =3D { =20 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *tab= le) { - struct fb_info *info =3D registered_fb[con2fb_map[vc->vc_num]]; + struct fb_info *info =3D fbcon_info_from_console(vc->vc_num); int i, j, k, depth; u8 val; =20 @@ -2651,7 +2663,7 @@ static void fbcon_modechanged(struct fb_info *info) return; vc =3D vc_cons[ops->currcon].d; if (vc->vc_mode !=3D KD_TEXT || - registered_fb[con2fb_map[ops->currcon]] !=3D info) + fbcon_info_from_console(ops->currcon) !=3D info) return; =20 p =3D &fb_display[vc->vc_num]; @@ -2691,7 +2703,7 @@ static void fbcon_set_all_vcs(struct fb_info *info) for (i =3D first_fb_vc; i <=3D last_fb_vc; i++) { vc =3D vc_cons[i].d; if (!vc || vc->vc_mode !=3D KD_TEXT || - registered_fb[con2fb_map[i]] !=3D info) + fbcon_info_from_console(i) !=3D info) continue; =20 if (con_is_visible(vc)) { @@ -2954,7 +2966,7 @@ void fbcon_fb_blanked(struct fb_info *info, int blank) =20 vc =3D vc_cons[ops->currcon].d; if (vc->vc_mode !=3D KD_TEXT || - registered_fb[con2fb_map[ops->currcon]] !=3D info) + fbcon_info_from_console(ops->currcon) !=3D info) return; =20 if (con_is_visible(vc)) { @@ -2974,7 +2986,7 @@ void fbcon_new_modelist(struct fb_info *info) const struct fb_videomode *mode; =20 for (i =3D first_fb_vc; i <=3D last_fb_vc; i++) { - if (registered_fb[con2fb_map[i]] !=3D info) + if (fbcon_info_from_console(i) !=3D info) continue; if (!fb_display[i].mode) continue; --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 C7637C433EF for ; Tue, 8 Feb 2022 22:30:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbiBHWaQ (ORCPT ); Tue, 8 Feb 2022 17:30:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386709AbiBHVIh (ORCPT ); Tue, 8 Feb 2022 16:08:37 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34C9BC0612BD for ; Tue, 8 Feb 2022 13:08:36 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id i15so608674wrb.3 for ; Tue, 08 Feb 2022 13:08:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4crFuo44YkHTtsyu93ovw2eXFVSYs3TA5dMCqcACcfE=; b=jQi7DARCTOMXz5tC+EIC8+SSebNsfkWcI1vfAOcJgnkqRbrl9Gbw9DcNTrzkF5/AM4 UoT9eQCdb6EjYX8w+Ub2a2EKqQNnkAABbTe0Xq0077w3volpOypc1EzJp4JNSjN1cszY SUvcPj044oQe627lpXmNgf2p1UJPbTY4Y4FlY= 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=4crFuo44YkHTtsyu93ovw2eXFVSYs3TA5dMCqcACcfE=; b=iteHe8FPUO8OIa0HPXDTF2AnUZlUNRots8biRR4gJghJUu65zkmje7v2YqgAILR71P XU6jb39T1pMDnujyWM7rpkLTdNf4+VzrDcdg5Uqb1MkhxegRFl2mVWuu6QHwNdYQaZpV cUf5iLdh6NQ+WIl0R0zX0BDrZUT5Mab+JwDzWtUhPXqzApR6KRwqTX3HyShx2GavXedM Od6vLKjT1MFqc3O/A3lKeR7367mHC6FnoQ8E/sPQsJF0hcx0nytKsmlr0Wv4k8qrKu/T hOMNZOXR9i1m8CZUI2zNtM3gfhg7LkMUl5uxFmWM6K1xovuU0hlIQZk82NL9jHEqy802 7Nww== X-Gm-Message-State: AOAM532DZVSFJGR+mru4/Ig0YjM5ZkSt6e9JMGMiY3QGSncfGn3MTdIE UY4uIfR+a7p7LlbVkJUFrp3s2g== X-Google-Smtp-Source: ABdhPJxyfY2skHNX0EzH+SvK1Ftr+4E95xGCkY+AUHxfLXuaNP8ZqaFebSt7JML9HJcvQyhPEOh1kA== X-Received: by 2002:a5d:6da8:: with SMTP id u8mr5134612wrs.362.1644354514804; Tue, 08 Feb 2022 13:08:34 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:34 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Helge Deller , Daniel Vetter , Claudio Suarez , Greg Kroah-Hartman , Tetsuo Handa , Du Cheng Subject: [PATCH v2 04/19] fbcon: delete delayed loading code Date: Tue, 8 Feb 2022 22:08:09 +0100 Message-Id: <20220208210824.2238981-5-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Before commit 6104c37094e729f3d4ce65797002112735d49cd1 Author: Daniel Vetter Date: Tue Aug 1 17:32:07 2017 +0200 fbcon: Make fbcon a built-time depency for fbdev it was possible to load fbcon and fbdev drivers in any order, which means that fbcon init had to handle the case where fbdev drivers where already registered. This is no longer possible, hence delete that code. Note that the exit case is a bit more complex and will be done in a separate patch. Since I had to audit the entire fbcon load code I also spotted a wrong function name in a comment in fbcon_startup(), which this patch also fixes. v2: Explain why we also fix the comment (Sam) Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Helge Deller Cc: Daniel Vetter Cc: Claudio Suarez Cc: Greg Kroah-Hartman Cc: Tetsuo Handa Cc: Du Cheng Acked-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index b75e638cb83d..83f0223f5333 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -944,7 +944,7 @@ static const char *fbcon_startup(void) return display_desc; /* * Instead of blindly using registered_fb[0], we use info_idx, set by - * fb_console_init(); + * fbcon_fb_registered(); */ info =3D registered_fb[info_idx]; if (!info) @@ -3299,17 +3299,6 @@ static void fbcon_start(void) return; } #endif - - if (num_registered_fb) { - int i; - - for_each_registered_fb(i) { - info_idx =3D i; - break; - } - - do_fbcon_takeover(0); - } } =20 static void fbcon_exit(void) --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 29FE7C43219 for ; Tue, 8 Feb 2022 22:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386500AbiBHWZr (ORCPT ); Tue, 8 Feb 2022 17:25:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386712AbiBHVIl (ORCPT ); Tue, 8 Feb 2022 16:08:41 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42295C0612B8 for ; Tue, 8 Feb 2022 13:08:40 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso1996710wmj.2 for ; Tue, 08 Feb 2022 13:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+/n/16RZ52OxmA0UdDabSATFo04ROfy75nWG7tM3V6I=; b=hRasZriqWBEeJzoUOLv/QgNtugplRHjEQRKqik65NeifTKzyRf0hhvBW1KWOkIoadP 3babK90zxgB9jGgUf/UNp4JC9Y+PrFYPgiRob7sYtSxpvX3uoVU0VosLdxIxxSp78Mvv nGxEaJzOsmX/d0hVbISOd5f0gVyHiJlADJFE4= 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=+/n/16RZ52OxmA0UdDabSATFo04ROfy75nWG7tM3V6I=; b=s01LMQKXAEd4+6r0T4GkZlVlHp/QREockh9/wher2pNYIuB7NSNIgvjgZTw4PvABmf 5Dr0DGxtOBS+BL+Y51j39jReNFphdqm0dNqrn2vBiQON4ychWIkG1VPewdb9lfgnmGHf TXZ9xWrlIKrk+2J01nWNTZNB9n3AEsKcJnsci8MUwXMg0TwC2k2XGDu33oQm/9Nel9w6 u51Yp3P6Bk9ANMUrHMX1PoMDnVN4JSYdAL2Zk2WRpWxTwYHUKLjIHvdMaE6ql/UF8nIn PghNb8Dj7Bzfh3AU9uVZX7m7RY+Rigm1lfth5e5vipsK+VYpC9RVKiKx5qfQBcSkG1UC 6Z7Q== X-Gm-Message-State: AOAM5310n/EdBsZhInrdhR8xBFzbW7EckUIjMvKsDq0+MrPMVLpY1inf KIjYYHJtntBt2wuvkTMdx3V54w== X-Google-Smtp-Source: ABdhPJxmKGvfzwrGcNB45zpKYvGa2R6htrHXkrCRtBsrNPeFRtFyXvFPfIN1bLeHK+Zv9iVuAwVA7Q== X-Received: by 2002:a1c:f60b:: with SMTP id w11mr2637250wmc.138.1644354518818; Tue, 08 Feb 2022 13:08:38 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:35 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Helge Deller , Daniel Vetter , Qing Wang Subject: [PATCH v2 05/19] fbdev/sysfs: Fix locking Date: Tue, 8 Feb 2022 22:08:10 +0100 Message-Id: <20220208210824.2238981-6-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" fb_set_var requires we hold the fb_info lock. Or at least this now matches what the ioctl does ... Note that ps3fb and sh_mobile_lcdcfb are busted in different ways here, but I will not fix them up. Also in practice this isn't a big deal, because really variable fbdev state is actually protected by console_lock (because fbcon just doesn't bother with lock_fb_info() at all), and lock_fb_info protecting anything is really just a neat lie. But that's a much bigger fish to fry. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Helge Deller Cc: Daniel Vetter Cc: Qing Wang Cc: Sam Ravnborg Acked-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbsysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/= fbsysfs.c index 26892940c213..8c1ee9ecec3d 100644 --- a/drivers/video/fbdev/core/fbsysfs.c +++ b/drivers/video/fbdev/core/fbsysfs.c @@ -91,9 +91,11 @@ static int activate(struct fb_info *fb_info, struct fb_v= ar_screeninfo *var) =20 var->activate |=3D FB_ACTIVATE_FORCE; console_lock(); + lock_fb_info(fb_info); err =3D fb_set_var(fb_info, var); if (!err) fbcon_update_vcs(fb_info, var->activate & FB_ACTIVATE_ALL); + unlock_fb_info(fb_info); console_unlock(); if (err) return err; --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 6F0D7C43217 for ; Tue, 8 Feb 2022 22:23:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386678AbiBHWW6 (ORCPT ); Tue, 8 Feb 2022 17:22:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386713AbiBHVIo (ORCPT ); Tue, 8 Feb 2022 16:08:44 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6512C0612B8 for ; Tue, 8 Feb 2022 13:08:43 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id k3-20020a1ca103000000b0037bdea84f9cso177060wme.1 for ; Tue, 08 Feb 2022 13:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A3tTnMr0uLBBq314Z85FYSlmwFIYVNy3yQwXAflpqNU=; b=TFb2QU3rtSHoVZdJiHVZvumnVkhInsk+wCMJg8P7UFjC0BxdSuwwm1lmgr39cTAQp0 ngMKu/F9v33MtAhNOOOaKSPVmb78N+5R1zMkbeg4XzZGw4nJ7Nwz4v8lcTDFwb8agLrw cdqX2t7ho1/lyYNo/mt86IWdCJimXrZ9E3cxE= 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=A3tTnMr0uLBBq314Z85FYSlmwFIYVNy3yQwXAflpqNU=; b=ppf1s+1YHvia8QbswHUHFjrhRzTlD3BI7OWFY9oD/rA0pDHLC0TNH7Vy4vNdK85UUl 3jTWb/jk8kdkz2Ps+XkS53oRjgXjy1VNjT2+lSIsrEu3yzB9NkmJg48dRhMgFxKZd3fi UaqQHf9d0+g30DPFhihlXKOVJWG3sshbrQ0MTb1pgI/lnYF8D40JhW3K5IIoLacZ3Wmf LuMFBaPIedepwSXEm20AQSBsujpfzzJF6DvD7CCZNNRklugLuCnVTO5kYvDzFCsms4fg qIkB5yzMcjTNVgvcAg0kkhVBnH28RYmDDqsJm6LgZXWFZL4bLNa4nvv2BM/s2n8wxro7 0iMA== X-Gm-Message-State: AOAM53222RibULugJ362680ccJ67N6aAS5dXWtOjpsfacxTgT8T6qsqf FFz6+TQDCBxj1IctRu/dg5b1FA== X-Google-Smtp-Source: ABdhPJy/MmzhXYLKsb7mnJJh9l95U3zWtlVma5KcWAwg0BTYSsMlJdIwPyk/OUMiHsCuauRvtiTE7Q== X-Received: by 2002:a05:600c:4ed3:: with SMTP id g19mr2625406wmq.186.1644354522253; Tue, 08 Feb 2022 13:08:42 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:40 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Daniel Vetter , Daniel Vetter , Claudio Suarez , Du Cheng , Thomas Zimmermann , Greg Kroah-Hartman , Tetsuo Handa Subject: [PATCH v2 06/19] fbcon: Use delayed work for cursor Date: Tue, 8 Feb 2022 22:08:11 +0100 Message-Id: <20220208210824.2238981-7-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Allows us to delete a bunch of hand-rolled stuff. Also to simplify the code we initialize the cursor_work completely when we allocate the fbcon_ops structure, instead of trying to cope with console re-initialization. The motiviation here is that fbcon code stops using the fb_info.queue, which helps with locking issues around cleanup and all that in a later patch. Also note that this allows us to ditch the hand-rolled work cleanup in fbcon_exit - we already call fbcon_del_cursor_timer, which takes care of everything. Plus this was racy anyway. Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Claudio Suarez Cc: Du Cheng Cc: Thomas Zimmermann Cc: Greg Kroah-Hartman Cc: Tetsuo Handa Acked-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas --- drivers/video/fbdev/core/fbcon.c | 85 +++++++++++++------------------- drivers/video/fbdev/core/fbcon.h | 4 +- 2 files changed, 35 insertions(+), 54 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 83f0223f5333..a368ed602e2e 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -350,8 +350,8 @@ static int get_color(struct vc_data *vc, struct fb_info= *info, =20 static void fb_flashcursor(struct work_struct *work) { - struct fb_info *info =3D container_of(work, struct fb_info, queue); - struct fbcon_ops *ops =3D info->fbcon_par; + struct fbcon_ops *ops =3D container_of(work, struct fbcon_ops, cursor_wor= k.work); + struct fb_info *info; struct vc_data *vc =3D NULL; int c; int mode; @@ -364,7 +364,10 @@ static void fb_flashcursor(struct work_struct *work) if (ret =3D=3D 0) return; =20 - if (ops && ops->currcon !=3D -1) + /* protected by console_lock */ + info =3D ops->info; + + if (ops->currcon !=3D -1) vc =3D vc_cons[ops->currcon].d; =20 if (!vc || !con_is_visible(vc) || @@ -380,42 +383,25 @@ static void fb_flashcursor(struct work_struct *work) ops->cursor(vc, info, mode, get_color(vc, info, c, 1), get_color(vc, info, c, 0)); console_unlock(); -} =20 -static void cursor_timer_handler(struct timer_list *t) -{ - struct fbcon_ops *ops =3D from_timer(ops, t, cursor_timer); - struct fb_info *info =3D ops->info; - - queue_work(system_power_efficient_wq, &info->queue); - mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies); + queue_delayed_work(system_power_efficient_wq, &ops->cursor_work, + ops->cur_blink_jiffies); } =20 -static void fbcon_add_cursor_timer(struct fb_info *info) +static void fbcon_add_cursor_work(struct fb_info *info) { struct fbcon_ops *ops =3D info->fbcon_par; =20 - if ((!info->queue.func || info->queue.func =3D=3D fb_flashcursor) && - !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) && - !fbcon_cursor_noblink) { - if (!info->queue.func) - INIT_WORK(&info->queue, fb_flashcursor); - - timer_setup(&ops->cursor_timer, cursor_timer_handler, 0); - mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies); - ops->flags |=3D FBCON_FLAGS_CURSOR_TIMER; - } + if (!fbcon_cursor_noblink) + queue_delayed_work(system_power_efficient_wq, &ops->cursor_work, + ops->cur_blink_jiffies); } =20 -static void fbcon_del_cursor_timer(struct fb_info *info) +static void fbcon_del_cursor_work(struct fb_info *info) { struct fbcon_ops *ops =3D info->fbcon_par; =20 - if (info->queue.func =3D=3D fb_flashcursor && - ops->flags & FBCON_FLAGS_CURSOR_TIMER) { - del_timer_sync(&ops->cursor_timer); - ops->flags &=3D ~FBCON_FLAGS_CURSOR_TIMER; - } + cancel_delayed_work_sync(&ops->cursor_work); } =20 #ifndef MODULE @@ -714,6 +700,8 @@ static int con2fb_acquire_newinfo(struct vc_data *vc, s= truct fb_info *info, ops =3D kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); if (!ops) err =3D -ENOMEM; + + INIT_DELAYED_WORK(&ops->cursor_work, fb_flashcursor); } =20 if (!err) { @@ -751,7 +739,7 @@ static int con2fb_release_oldinfo(struct vc_data *vc, s= truct fb_info *oldinfo, } =20 if (!err) { - fbcon_del_cursor_timer(oldinfo); + fbcon_del_cursor_work(oldinfo); kfree(ops->cursor_state.mask); kfree(ops->cursor_data); kfree(ops->cursor_src); @@ -867,7 +855,7 @@ static int set_con2fb_map(int unit, int newidx, int use= r) logo_shown !=3D FBCON_LOGO_DONTSHOW); =20 if (!found) - fbcon_add_cursor_timer(info); + fbcon_add_cursor_work(info); con2fb_map_boot[unit] =3D newidx; con2fb_init_display(vc, info, unit, show_logo); } @@ -964,6 +952,8 @@ static const char *fbcon_startup(void) return NULL; } =20 + INIT_DELAYED_WORK(&ops->cursor_work, fb_flashcursor); + ops->currcon =3D -1; ops->graphics =3D 1; ops->cur_rotate =3D -1; @@ -1006,7 +996,7 @@ static const char *fbcon_startup(void) info->var.yres, info->var.bits_per_pixel); =20 - fbcon_add_cursor_timer(info); + fbcon_add_cursor_work(info); return display_desc; } =20 @@ -1194,7 +1184,7 @@ static void fbcon_deinit(struct vc_data *vc) goto finished; =20 if (con_is_visible(vc)) - fbcon_del_cursor_timer(info); + fbcon_del_cursor_work(info); =20 ops->flags &=3D ~FBCON_FLAGS_INIT; finished: @@ -1320,9 +1310,9 @@ static void fbcon_cursor(struct vc_data *vc, int mode) return; =20 if (vc->vc_cursor_type & CUR_SW) - fbcon_del_cursor_timer(info); + fbcon_del_cursor_work(info); else - fbcon_add_cursor_timer(info); + fbcon_add_cursor_work(info); =20 ops->cursor_flash =3D (mode =3D=3D CM_ERASE) ? 0 : 1; =20 @@ -2132,14 +2122,14 @@ static int fbcon_switch(struct vc_data *vc) } =20 if (old_info !=3D info) - fbcon_del_cursor_timer(old_info); + fbcon_del_cursor_work(old_info); } =20 if (fbcon_is_inactive(vc, info) || ops->blank_state !=3D FB_BLANK_UNBLANK) - fbcon_del_cursor_timer(info); + fbcon_del_cursor_work(info); else - fbcon_add_cursor_timer(info); + fbcon_add_cursor_work(info); =20 set_blitting_type(vc, info); ops->cursor_reset =3D 1; @@ -2247,9 +2237,9 @@ static int fbcon_blank(struct vc_data *vc, int blank,= int mode_switch) =20 if (mode_switch || fbcon_is_inactive(vc, info) || ops->blank_state !=3D FB_BLANK_UNBLANK) - fbcon_del_cursor_timer(info); + fbcon_del_cursor_work(info); else - fbcon_add_cursor_timer(info); + fbcon_add_cursor_work(info); =20 return 0; } @@ -3181,7 +3171,7 @@ static ssize_t show_cursor_blink(struct device *devic= e, if (!ops) goto err; =20 - blink =3D (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0; + blink =3D delayed_work_pending(&ops->cursor_work); err: console_unlock(); return snprintf(buf, PAGE_SIZE, "%d\n", blink); @@ -3210,10 +3200,10 @@ static ssize_t store_cursor_blink(struct device *de= vice, =20 if (blink) { fbcon_cursor_noblink =3D 0; - fbcon_add_cursor_timer(info); + fbcon_add_cursor_work(info); } else { fbcon_cursor_noblink =3D 1; - fbcon_del_cursor_timer(info); + fbcon_del_cursor_work(info); } =20 err: @@ -3314,15 +3304,9 @@ static void fbcon_exit(void) #endif =20 for_each_registered_fb(i) { - int pending =3D 0; - mapped =3D 0; info =3D registered_fb[i]; =20 - if (info->queue.func) - pending =3D cancel_work_sync(&info->queue); - pr_debug("fbcon: %s pending work\n", (pending ? "canceled" : "no")); - for (j =3D first_fb_vc; j <=3D last_fb_vc; j++) { if (con2fb_map[j] =3D=3D i) { mapped =3D 1; @@ -3338,15 +3322,12 @@ static void fbcon_exit(void) if (info->fbcon_par) { struct fbcon_ops *ops =3D info->fbcon_par; =20 - fbcon_del_cursor_timer(info); + fbcon_del_cursor_work(info); kfree(ops->cursor_src); kfree(ops->cursor_state.mask); kfree(info->fbcon_par); info->fbcon_par =3D NULL; } - - if (info->queue.func =3D=3D fb_flashcursor) - info->queue.func =3D NULL; } } } diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fb= con.h index 969d41ecede5..6708ca0048aa 100644 --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -14,11 +14,11 @@ #include #include #include +#include =20 #include =20 #define FBCON_FLAGS_INIT 1 -#define FBCON_FLAGS_CURSOR_TIMER 2 =20 /* * This is the interface between the low-level console driver and the @@ -68,7 +68,7 @@ struct fbcon_ops { int (*update_start)(struct fb_info *info); int (*rotate_font)(struct fb_info *info, struct vc_data *vc); struct fb_var_screeninfo var; /* copy of the current fb_var_screeninfo */ - struct timer_list cursor_timer; /* Cursor timer */ + struct delayed_work cursor_work; /* Cursor timer */ struct fb_cursor cursor_state; struct fbcon_display *p; struct fb_info *info; --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 2D91DC3527E for ; Tue, 8 Feb 2022 22:26:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387665AbiBHW0B (ORCPT ); Tue, 8 Feb 2022 17:26:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386717AbiBHVIp (ORCPT ); Tue, 8 Feb 2022 16:08:45 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0171C0612BC for ; Tue, 8 Feb 2022 13:08:44 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso1996783wmj.2 for ; Tue, 08 Feb 2022 13:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gS4cB1np1M5WffNPCk4lBUp+Ft8dXY94oZrLVYHaHIU=; b=POlHKow3MVpKZFu37kNTQBf60vXI/Bdf0/kdIpeZxBk+FetbUOq7GWpdR/E7ywdHH6 6A8znecVyMGtnphv3jPdoQeC1TZW2v3uwbFzVY/WoLwOj8AtjmVGu62bi97NgT0FawcD T1Dvp2sActs5q6ehz/awhILYoFHe66ZE+SqPM= 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=gS4cB1np1M5WffNPCk4lBUp+Ft8dXY94oZrLVYHaHIU=; b=qLTzqJSq4Azr/5ciU0xB0oh9Sp5YVZlHdEKJyAaxxkv3I/NCblrBYCWKgQyHzIMl5v cwEjc0SDlMOLzWvQ4iclRNhi+leNAOLSiJyg3JtYXxUSXhzYokQde/z8CzbTooPsnxcF ZS4O2o3HrjQWvWATRsH/RanfepoKHjUQJednde6mfqVXD+KtX9Cejv1kDdX1hRlkKA+7 vJxvKdAt/kxCjlPYwyqLXo/p98u+KGfgNclJn5RHwtNf0DCbqn1JBovRyCoxreZUcnuH 6KGh3Sij12D3a65V0vPb9oMajVHaFfpxcANwVjDZVymScPBbCsIguISeXZZxcoEbXngt 6roQ== X-Gm-Message-State: AOAM533YrghMFzqoOlj88yKBjphAxdSgSd1ZG3e6wry6g6LMsqJY55sE AYESCV3eIc4pCzvoHwiGINi5kw== X-Google-Smtp-Source: ABdhPJw/XJ2Q8Ob/zJyksXM8gBtUTQabIf26mhSeRQ5qUe8UkM0HAwCg61/bEu2b1DdCs9/6qE+0Ng== X-Received: by 2002:a05:600c:3505:: with SMTP id h5mr2617699wmq.122.1644354523501; Tue, 08 Feb 2022 13:08:43 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:42 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Thomas Zimmermann , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Tetsuo Handa , Greg Kroah-Hartman , Du Cheng , Claudio Suarez Subject: [PATCH v2 07/19] fbcon: Replace FBCON_FLAGS_INIT with a boolean Date: Tue, 8 Feb 2022 22:08:12 +0100 Message-Id: <20220208210824.2238981-8-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" It's only one flag and slightly tidier code. Acked-by: Thomas Zimmermann Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Tetsuo Handa Cc: Greg Kroah-Hartman Cc: Du Cheng Cc: Thomas Zimmermann Cc: Claudio Suarez --- drivers/video/fbdev/core/fbcon.c | 11 +++++------ drivers/video/fbdev/core/fbcon.h | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index a368ed602e2e..058e885d24f6 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -775,7 +775,7 @@ static void con2fb_init_display(struct vc_data *vc, str= uct fb_info *info, =20 ops->currcon =3D fg_console; =20 - if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) { + if (info->fbops->fb_set_par && !ops->initialized) { ret =3D info->fbops->fb_set_par(info); =20 if (ret) @@ -784,7 +784,7 @@ static void con2fb_init_display(struct vc_data *vc, str= uct fb_info *info, "error code %d\n", ret); } =20 - ops->flags |=3D FBCON_FLAGS_INIT; + ops->initialized =3D true; ops->graphics =3D 0; fbcon_set_disp(info, &info->var, unit); =20 @@ -1103,8 +1103,7 @@ static void fbcon_init(struct vc_data *vc, int init) * We need to do it in fbcon_init() to prevent screen corruption. */ if (con_is_visible(vc) && vc->vc_mode =3D=3D KD_TEXT) { - if (info->fbops->fb_set_par && - !(ops->flags & FBCON_FLAGS_INIT)) { + if (info->fbops->fb_set_par && !ops->initialized) { ret =3D info->fbops->fb_set_par(info); =20 if (ret) @@ -1113,7 +1112,7 @@ static void fbcon_init(struct vc_data *vc, int init) "error code %d\n", ret); } =20 - ops->flags |=3D FBCON_FLAGS_INIT; + ops->initialized =3D true; } =20 ops->graphics =3D 0; @@ -1186,7 +1185,7 @@ static void fbcon_deinit(struct vc_data *vc) if (con_is_visible(vc)) fbcon_del_cursor_work(info); =20 - ops->flags &=3D ~FBCON_FLAGS_INIT; + ops->initialized =3D false; finished: =20 fbcon_free_font(p, free_font); diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fb= con.h index 6708ca0048aa..0eaf54a21151 100644 --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -18,8 +18,6 @@ =20 #include =20 -#define FBCON_FLAGS_INIT 1 - /* * This is the interface between the low-level console driver and the * low-level frame buffer device @@ -79,7 +77,7 @@ struct fbcon_ops { int blank_state; int graphics; int save_graphics; /* for debug enter/leave */ - int flags; + bool initialized; int rotate; int cur_rotate; char *cursor_data; --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 DE478C433FE for ; Tue, 8 Feb 2022 22:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387343AbiBHWgC (ORCPT ); Tue, 8 Feb 2022 17:36:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386718AbiBHVIq (ORCPT ); Tue, 8 Feb 2022 16:08:46 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFA69C0612BA for ; Tue, 8 Feb 2022 13:08:45 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id q198-20020a1ca7cf000000b0037bb52545c6so2005320wme.1 for ; Tue, 08 Feb 2022 13:08:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kxmmBkNFc2e7V4ERjxKal7nxxEacNSK1FsSHDJ/tyIc=; b=Z09sK1MIQXvHodEW69pcLwZPAC2Jyh1Yq9ldGqdLR7reUraZE7M6u7jdOOeYRDBf89 UUxkLMzeLBfxd3O4D0f+4VPHvHICjubc4fPRQHDK7GB4hbBxyg8oSXZLVun1qG1/NbkT QOvr5w/LmHavg6G1SUwn1zrJxyAMEJXhXZfiY= 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=kxmmBkNFc2e7V4ERjxKal7nxxEacNSK1FsSHDJ/tyIc=; b=mH0hyNblSkMhY4dYGCezzYJJZpQ7piL205VBsArfARf6wBMru1Nn4nxyQfu8Pnbh3U Xuw/fw1rqI8Wykl8fq1/RmWDdqL1uRXVPRLElUxP5SUmbBcpUSWx2p0Skc4TkBWwzZ4A PRLQ50+N400VF6c0coJR2dV/nVSckrXQlVcLknb1LNlHbLFUIF5gjxi+9trZAC6DJkMY /0UouuAtAdsRSyF1Phwa3NwpAhzyX9elQ1LWNpkw2r9NnksYovb3WRX7at2ciiV/bMPL UbFmCXlw5BhOqcUTx+YgeG5YIRZCw3mMOEBvfBrPIWeUPl9j169YlRFTHIBcgDNTAM1U yPPQ== X-Gm-Message-State: AOAM531NQRqACVJleV8CAHAxY1tvOefP+IqX7h6jusoflt7bFdLsRibQ KeBb6boCsKrIvjmNHaRTRShySw== X-Google-Smtp-Source: ABdhPJx9Pmbs1AtHCBnIRUQUhg6MOdNihnyQs/peWemRHhguZJlE+pEmulNqns55/ByeHXTnphkZ2g== X-Received: by 2002:a05:600c:3394:: with SMTP id o20mr2536218wmp.186.1644354524370; Tue, 08 Feb 2022 13:08:44 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:44 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Helge Deller Subject: [PATCH v2 08/19] fb: Delete fb_info->queue Date: Tue, 8 Feb 2022 22:08:13 +0100 Message-Id: <20220208210824.2238981-9-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" It was only used by fbcon, and that now switched to its own, private work. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Helge Deller Cc: linux-fbdev@vger.kernel.org Acked-by: Thomas Zimmermann --- include/linux/fb.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/fb.h b/include/linux/fb.h index 3d7306c9a706..23b19cf8bccd 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -449,7 +449,6 @@ struct fb_info { struct fb_var_screeninfo var; /* Current var */ struct fb_fix_screeninfo fix; /* Current fix */ struct fb_monspecs monspecs; /* Current Monitor specs */ - struct work_struct queue; /* Framebuffer event queue */ struct fb_pixmap pixmap; /* Image hardware mapper */ struct fb_pixmap sprite; /* Cursor hardware mapper */ struct fb_cmap cmap; /* Current cmap */ --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 C0A24C4332F for ; Tue, 8 Feb 2022 22:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387749AbiBHWbg (ORCPT ); Tue, 8 Feb 2022 17:31:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386721AbiBHVIs (ORCPT ); Tue, 8 Feb 2022 16:08:48 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 173AFC0612B8 for ; Tue, 8 Feb 2022 13:08:48 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id m126-20020a1ca384000000b0037bb8e379feso1986185wme.5 for ; Tue, 08 Feb 2022 13:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZpkV0RtV6b+qoZSx1q7At4dbITHQdztu2MpUTGszUSQ=; b=XBxwj0okLWcXjnLZC8VylTpr8kVr/cRQvzFH0baQxLV3Ag48btF75FnQSiNzw2+6VD mv4OqAjPHJGITMkt/3V8/uxvtQ0r4+UQCO5GX+qxMgmsCuyTs0uabU9J7oJGYb8c6Iow n/zSAwN9FJlnot4fK6xQ8YNOvjOBpzPLNjj0c= 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=ZpkV0RtV6b+qoZSx1q7At4dbITHQdztu2MpUTGszUSQ=; b=L21pFy/dzozmNxgvh4yAamQs5yGCPYthH+RTAVQOLJ5o+raTU4Dvo49oXgv/b7fEI0 T6WAwvc7r1/3zJ0vRLNvg8jF47va+Uol86qDwGpb5lZ2zngt/GFdOwVnGUyMHN7TW4IS xtCwa8VpGCWT+6gCey9hRgJe2W1PoSgYZTHavmFRWUldkmda0hoeQp2G42fd0NYtiQDA 0RTSmsisq3qlNcnkkDm3lquYDvqRjFFuKnPj5ovYZUqwlGMro+arEkZ5UMBjZt2ukFfr cGvj2Qi/yuZfdTPNFqqcXk0K1ElvzYUAgcPgyzevzCawmyuYr9qqJV7v+/Rfg5E8LFLK T43w== X-Gm-Message-State: AOAM532BfReVwEpAX2fo0w0SeCws5JmnpRrB1ygwcJDr6CXoCkjgJIrO x91RhrX4nh4qjGJyfBArQd4XEw== X-Google-Smtp-Source: ABdhPJynSn4cJJu2QmKl6qJIPVpol64suJAmeSMzFGBHBZrxWj3fvOdAZeounKrNlr8/sZP5nXwPjQ== X-Received: by 2002:a05:600c:308:: with SMTP id q8mr2548459wmd.71.1644354526664; Tue, 08 Feb 2022 13:08:46 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:44 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Claudio Suarez , Greg Kroah-Hartman , Tetsuo Handa , Du Cheng Subject: [PATCH v2 09/19] fbcon: Extract fbcon_open/release helpers Date: Tue, 8 Feb 2022 22:08:14 +0100 Message-Id: <20220208210824.2238981-10-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" There's two minor behaviour changes in here: - in error paths we now consistently call fb_ops->fb_release - fb_release really can't fail (fbmem.c ignores it too) and there's no reasonable cleanup we can do anyway. Note that everything in fbcon.c is protected by the big console_lock() lock (especially all the global variables), so the minor changes in ordering of setup/cleanup do not matter. v2: Explain a bit better why this is all correct (Sam) Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Claudio Suarez Cc: Greg Kroah-Hartman Cc: Tetsuo Handa Cc: Du Cheng --- drivers/video/fbdev/core/fbcon.c | 107 +++++++++++++++---------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 058e885d24f6..3e1a3e7bf527 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -682,19 +682,37 @@ static int fbcon_invalid_charcount(struct fb_info *in= fo, unsigned charcount) =20 #endif /* CONFIG_MISC_TILEBLITTING */ =20 +static int fbcon_open(struct fb_info *info) +{ + if (!try_module_get(info->fbops->owner)) + return -ENODEV; + + if (info->fbops->fb_open && + info->fbops->fb_open(info, 0)) { + module_put(info->fbops->owner); + return -ENODEV; + } + + return 0; +} + +static void fbcon_release(struct fb_info *info) +{ + if (info->fbops->fb_release) + info->fbops->fb_release(info, 0); + + module_put(info->fbops->owner); +} =20 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info, int unit, int oldidx) { struct fbcon_ops *ops =3D NULL; - int err =3D 0; - - if (!try_module_get(info->fbops->owner)) - err =3D -ENODEV; + int err; =20 - if (!err && info->fbops->fb_open && - info->fbops->fb_open(info, 0)) - err =3D -ENODEV; + err =3D fbcon_open(info); + if (err) + return err; =20 if (!err) { ops =3D kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); @@ -715,7 +733,7 @@ static int con2fb_acquire_newinfo(struct vc_data *vc, s= truct fb_info *info, =20 if (err) { con2fb_map[unit] =3D oldidx; - module_put(info->fbops->owner); + fbcon_release(info); } =20 return err; @@ -726,45 +744,34 @@ static int con2fb_release_oldinfo(struct vc_data *vc,= struct fb_info *oldinfo, int oldidx, int found) { struct fbcon_ops *ops =3D oldinfo->fbcon_par; - int err =3D 0, ret; + int ret; =20 - if (oldinfo->fbops->fb_release && - oldinfo->fbops->fb_release(oldinfo, 0)) { - con2fb_map[unit] =3D oldidx; - if (!found && newinfo->fbops->fb_release) - newinfo->fbops->fb_release(newinfo, 0); - if (!found) - module_put(newinfo->fbops->owner); - err =3D -ENODEV; - } + fbcon_release(oldinfo); =20 - if (!err) { - fbcon_del_cursor_work(oldinfo); - kfree(ops->cursor_state.mask); - kfree(ops->cursor_data); - kfree(ops->cursor_src); - kfree(ops->fontbuffer); - kfree(oldinfo->fbcon_par); - oldinfo->fbcon_par =3D NULL; - module_put(oldinfo->fbops->owner); - /* - If oldinfo and newinfo are driving the same hardware, - the fb_release() method of oldinfo may attempt to - restore the hardware state. This will leave the - newinfo in an undefined state. Thus, a call to - fb_set_par() may be needed for the newinfo. - */ - if (newinfo && newinfo->fbops->fb_set_par) { - ret =3D newinfo->fbops->fb_set_par(newinfo); + fbcon_del_cursor_work(oldinfo); + kfree(ops->cursor_state.mask); + kfree(ops->cursor_data); + kfree(ops->cursor_src); + kfree(ops->fontbuffer); + kfree(oldinfo->fbcon_par); + oldinfo->fbcon_par =3D NULL; + /* + If oldinfo and newinfo are driving the same hardware, + the fb_release() method of oldinfo may attempt to + restore the hardware state. This will leave the + newinfo in an undefined state. Thus, a call to + fb_set_par() may be needed for the newinfo. + */ + if (newinfo && newinfo->fbops->fb_set_par) { + ret =3D newinfo->fbops->fb_set_par(newinfo); =20 - if (ret) - printk(KERN_ERR "con2fb_release_oldinfo: " - "detected unhandled fb_set_par error, " - "error code %d\n", ret); - } + if (ret) + printk(KERN_ERR "con2fb_release_oldinfo: " + "detected unhandled fb_set_par error, " + "error code %d\n", ret); } =20 - return err; + return 0; } =20 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info, @@ -919,7 +926,6 @@ static const char *fbcon_startup(void) struct fbcon_display *p =3D &fb_display[fg_console]; struct vc_data *vc =3D vc_cons[fg_console].d; const struct font_desc *font =3D NULL; - struct module *owner; struct fb_info *info =3D NULL; struct fbcon_ops *ops; int rows, cols; @@ -938,17 +944,12 @@ static const char *fbcon_startup(void) if (!info) return NULL; =09 - owner =3D info->fbops->owner; - if (!try_module_get(owner)) + if (fbcon_open(info)) return NULL; - if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) { - module_put(owner); - return NULL; - } =20 ops =3D kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); if (!ops) { - module_put(owner); + fbcon_release(info); return NULL; } =20 @@ -3314,10 +3315,6 @@ static void fbcon_exit(void) } =20 if (mapped) { - if (info->fbops->fb_release) - info->fbops->fb_release(info, 0); - module_put(info->fbops->owner); - if (info->fbcon_par) { struct fbcon_ops *ops =3D info->fbcon_par; =20 @@ -3327,6 +3324,8 @@ static void fbcon_exit(void) kfree(info->fbcon_par); info->fbcon_par =3D NULL; } + + fbcon_release(info); } } } --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 107EDC433EF for ; Tue, 8 Feb 2022 22:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386961AbiBHWfh (ORCPT ); Tue, 8 Feb 2022 17:35:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386725AbiBHVIu (ORCPT ); Tue, 8 Feb 2022 16:08:50 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 537EEC0612BA for ; Tue, 8 Feb 2022 13:08:49 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id l67-20020a1c2546000000b00353951c3f62so153819wml.5 for ; Tue, 08 Feb 2022 13:08:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0jcZhW240q/V+F937iAT51+jAJ4wMTWthnKOU1oFwYY=; b=RvN9RXsH98HQ7R4ASK94Wa721S7v3e9uYupFyjpxCVnHmyUZk9Z0e0fiSif0AsX195 hJ8mBsbov8YE3ijlPln772kRVM7ChshKzGAhsKXYeIBbkNk0RX0OB2TONi3m39pCKQhc m8pJ7WEZ//h8h6RloxQYTj4Gg7Q9rT68dL5eI= 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=0jcZhW240q/V+F937iAT51+jAJ4wMTWthnKOU1oFwYY=; b=kpdZzWoiYvXlK/f4PcA02jOhSw9jfG/H9DNclC1xXZOVlorZtpsP9qE6hYTNGmWLMG NMS7Aghe6V6QN57LlPvmTRtSvnvXJMXdh/2XYVg/sPZO4nrFJUNdyd8GkjuXmYc0zhNw 7xfxCs2bgTs8NQ3ym9VrZ8SJXDWaA1F4dmEyZZMUr1T0XY4gDYDIgk6fr5LX9HxQ2+Fj 7wvFabzMYEMRyp4uPx4eWIbupir98V5wQV1t6fSRAFwVxBeHbbnYhUVyU2VFRkQjwhxL vySpvvIo7iwLt69cka9Ic9jAHwBdib8QaKrm7KQQ9Qn11OfSz516uDG8AdeSlssTofdR hhNQ== X-Gm-Message-State: AOAM532J2W+TDkF8+tH8UvFenDLpZfc0fUmLGrFCMazMAqBTT94zDLFQ 23fJUu+ofKZCqWfltDDJhUNwOw== X-Google-Smtp-Source: ABdhPJwMORQTpYifpLCGD22BDyRns4eEbj+NoYV/5vmbXl7M9Sj9oFb03bz6IHoMsQGBTHnNyzmopg== X-Received: by 2002:a05:600c:3848:: with SMTP id s8mr2565869wmr.151.1644354527869; Tue, 08 Feb 2022 13:08:47 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:47 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Thomas Zimmermann , Greg Kroah-Hartman , Claudio Suarez , Du Cheng , Tetsuo Handa Subject: [PATCH v2 10/19] fbcon: Ditch error handling for con2fb_release_oldinfo Date: Tue, 8 Feb 2022 22:08:15 +0100 Message-Id: <20220208210824.2238981-11-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" It doesn't ever fail anymore. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Greg Kroah-Hartman Cc: Claudio Suarez Cc: Du Cheng Cc: Tetsuo Handa Acked-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.c | 37 +++++++++++--------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 3e1a3e7bf527..a60891005d44 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -739,9 +739,8 @@ static int con2fb_acquire_newinfo(struct vc_data *vc, s= truct fb_info *info, return err; } =20 -static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldi= nfo, - struct fb_info *newinfo, int unit, - int oldidx, int found) +static void con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *old= info, + struct fb_info *newinfo) { struct fbcon_ops *ops =3D oldinfo->fbcon_par; int ret; @@ -770,8 +769,6 @@ static int con2fb_release_oldinfo(struct vc_data *vc, s= truct fb_info *oldinfo, "detected unhandled fb_set_par error, " "error code %d\n", ret); } - - return 0; } =20 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info, @@ -825,7 +822,7 @@ static int set_con2fb_map(int unit, int newidx, int use= r) int oldidx =3D con2fb_map[unit]; struct fb_info *info =3D registered_fb[newidx]; struct fb_info *oldinfo =3D NULL; - int found, err =3D 0; + int found, err =3D 0, show_logo; =20 WARN_CONSOLE_UNLOCKED(); =20 @@ -854,18 +851,15 @@ static int set_con2fb_map(int unit, int newidx, int u= ser) * fbcon should release it. */ if (!err && oldinfo && !search_fb_in_map(oldidx)) - err =3D con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx, - found); + con2fb_release_oldinfo(vc, oldinfo, info); =20 - if (!err) { - int show_logo =3D (fg_console =3D=3D 0 && !user && - logo_shown !=3D FBCON_LOGO_DONTSHOW); + show_logo =3D (fg_console =3D=3D 0 && !user && + logo_shown !=3D FBCON_LOGO_DONTSHOW); =20 - if (!found) - fbcon_add_cursor_work(info); - con2fb_map_boot[unit] =3D newidx; - con2fb_init_display(vc, info, unit, show_logo); - } + if (!found) + fbcon_add_cursor_work(info); + con2fb_map_boot[unit] =3D newidx; + con2fb_init_display(vc, info, unit, show_logo); =20 if (!search_fb_in_map(info_idx)) info_idx =3D newidx; @@ -2769,7 +2763,7 @@ static inline void fbcon_unbind(void) {} /* called with console_lock held */ void fbcon_fb_unbind(struct fb_info *info) { - int i, new_idx =3D -1, ret =3D 0; + int i, new_idx =3D -1; int idx =3D info->node; =20 WARN_CONSOLE_UNLOCKED(); @@ -2803,13 +2797,8 @@ void fbcon_fb_unbind(struct fb_info *info) if (con2fb_map[i] =3D=3D idx) { con2fb_map[i] =3D -1; if (!search_fb_in_map(idx)) { - ret =3D con2fb_release_oldinfo(vc_cons[i].d, - info, NULL, i, - idx, 0); - if (ret) { - con2fb_map[i] =3D idx; - return; - } + con2fb_release_oldinfo(vc_cons[i].d, + info, NULL); } } } --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 9889FC35274 for ; Tue, 8 Feb 2022 22:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388363AbiBHWcq (ORCPT ); Tue, 8 Feb 2022 17:32:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386726AbiBHVIv (ORCPT ); Tue, 8 Feb 2022 16:08:51 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6452BC0612BC for ; Tue, 8 Feb 2022 13:08:50 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id s10so591417wra.5 for ; Tue, 08 Feb 2022 13:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a7btPFkxjvf2mfzDClUDZxd+ZY9UWGCKfTqWfIAGZE4=; b=hC3hy+RQU0IwCFFhPrwVyJ7y2LIZTcjUzkEUlkvoHv0+/idoFt5rzVLYgDfL/hgQIi i2eeoFzpPEkt5fIvytjXjxYMYBVzGR7jyva3sSvlFHwg+sOFZrStM/ihrh+FHInpCE0T P8beATlmu3Ae4wYaareiwO9PDCh36eixaQNpw= 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=a7btPFkxjvf2mfzDClUDZxd+ZY9UWGCKfTqWfIAGZE4=; b=VbrNtW7tn2AOf3/tbnOhRKT+2f9spv1mOibtKiZDGt6GtpKGpQoGeeo9nKfQvKFIQH CHw8+ag2zVGumtWWhkrmNTC31CmSFw5k6oBcOW0AVL/D93oVj1jCVPg5jgW0+TfmEbdT J/LLi93bQPRZWkS3n+W5ds6VigxidfhZh1MPMG/K4HcoSwfT7VUYM2lrbHISfsoNZk8i 5ktUkR1dhVfrNcx8/kQ7D8On3WCbUCAUsU0eU5I3seZxG8dkLBjRTabGSc8nngagV0eI Y6sJikAFq5loe5iv+RI0Dr+lRSObGirWLdz8WGLMuxz5x9OEu4kBeKWEcccZjqTmp+Gt cG8g== X-Gm-Message-State: AOAM530hcJ3FMIe39XKishw8dOYjZxYnmnEWXKFinVGShRlLI8TGR+p2 Q555cHRrXMuCrDAnfegsg7atlQ== X-Google-Smtp-Source: ABdhPJxeKo6oxb1DStpx7vg2vbnJEG3khQpC5Pgmw0k9BwE0aQ7ghCQbgGVL5nA7XrrUJ87c2ZVJ6w== X-Received: by 2002:a5d:4528:: with SMTP id j8mr5046963wra.544.1644354528995; Tue, 08 Feb 2022 13:08:48 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:48 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , kernel test robot , Daniel Vetter , Daniel Vetter , Greg Kroah-Hartman , Tetsuo Handa , Thomas Zimmermann , Claudio Suarez , Du Cheng Subject: [PATCH v2 11/19] fbcon: move more common code into fb_open() Date: Tue, 8 Feb 2022 22:08:16 +0100 Message-Id: <20220208210824.2238981-12-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" No idea why con2fb_acquire_newinfo() initializes much less than fbcon_startup(), but so be it. From a quick look most of the un-initialized stuff should be fairly harmless, but who knows. Note that the error handling for the con2fb_acquire_newinfo() failure case was very strange: Callers updated con2fb_map to the new value before calling this function, but upon error con2fb_acquire_newinfo reset it to the old value. Since I removed the call to fbcon_release anyway that strange error path was sticking out like a sore thumb, hence I removed it. Which also allows us to remove the oldidx parameter from that function. v2: Explain what's going on with oldidx and error paths (Sam) v3: Drop unused variable (0day) Acked-by: Sam Ravnborg (v2) Cc: kernel test robot Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Greg Kroah-Hartman Cc: Tetsuo Handa Cc: Thomas Zimmermann Cc: Claudio Suarez Cc: Du Cheng Acked-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.c | 75 +++++++++++++------------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index a60891005d44..f0213a0e3870 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -682,8 +682,18 @@ static int fbcon_invalid_charcount(struct fb_info *inf= o, unsigned charcount) =20 #endif /* CONFIG_MISC_TILEBLITTING */ =20 +static void fbcon_release(struct fb_info *info) +{ + if (info->fbops->fb_release) + info->fbops->fb_release(info, 0); + + module_put(info->fbops->owner); +} + static int fbcon_open(struct fb_info *info) { + struct fbcon_ops *ops; + if (!try_module_get(info->fbops->owner)) return -ENODEV; =20 @@ -693,48 +703,31 @@ static int fbcon_open(struct fb_info *info) return -ENODEV; } =20 - return 0; -} + ops =3D kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); + if (!ops) { + fbcon_release(info); + return -ENOMEM; + } =20 -static void fbcon_release(struct fb_info *info) -{ - if (info->fbops->fb_release) - info->fbops->fb_release(info, 0); + INIT_DELAYED_WORK(&ops->cursor_work, fb_flashcursor); + ops->info =3D info; + info->fbcon_par =3D ops; + ops->cur_blink_jiffies =3D HZ / 5; =20 - module_put(info->fbops->owner); + return 0; } =20 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info, - int unit, int oldidx) + int unit) { - struct fbcon_ops *ops =3D NULL; int err; =20 err =3D fbcon_open(info); if (err) return err; =20 - if (!err) { - ops =3D kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); - if (!ops) - err =3D -ENOMEM; - - INIT_DELAYED_WORK(&ops->cursor_work, fb_flashcursor); - } - - if (!err) { - ops->cur_blink_jiffies =3D HZ / 5; - ops->info =3D info; - info->fbcon_par =3D ops; - - if (vc) - set_blitting_type(vc, info); - } - - if (err) { - con2fb_map[unit] =3D oldidx; - fbcon_release(info); - } + if (vc) + set_blitting_type(vc, info); =20 return err; } @@ -842,9 +835,11 @@ static int set_con2fb_map(int unit, int newidx, int us= er) =20 found =3D search_fb_in_map(newidx); =20 - con2fb_map[unit] =3D newidx; - if (!err && !found) - err =3D con2fb_acquire_newinfo(vc, info, unit, oldidx); + if (!err && !found) { + err =3D con2fb_acquire_newinfo(vc, info, unit); + if (!err) + con2fb_map[unit] =3D newidx; + } =20 /* * If old fb is not mapped to any of the consoles, @@ -941,20 +936,10 @@ static const char *fbcon_startup(void) if (fbcon_open(info)) return NULL; =20 - ops =3D kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); - if (!ops) { - fbcon_release(info); - return NULL; - } - - INIT_DELAYED_WORK(&ops->cursor_work, fb_flashcursor); - + ops =3D info->fbcon_par; ops->currcon =3D -1; ops->graphics =3D 1; ops->cur_rotate =3D -1; - ops->cur_blink_jiffies =3D HZ / 5; - ops->info =3D info; - info->fbcon_par =3D ops; =20 p->con_rotate =3D initial_rotation; if (p->con_rotate =3D=3D -1) @@ -1024,7 +1009,7 @@ static void fbcon_init(struct vc_data *vc, int init) return; =20 if (!info->fbcon_par) - con2fb_acquire_newinfo(vc, info, vc->vc_num, -1); + con2fb_acquire_newinfo(vc, info, vc->vc_num); =20 /* If we are not the first console on this fb, copy the font from that console */ --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 5B6B1C433EF for ; Tue, 8 Feb 2022 22:30:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386350AbiBHWaL (ORCPT ); Tue, 8 Feb 2022 17:30:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386731AbiBHVIw (ORCPT ); Tue, 8 Feb 2022 16:08:52 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA982C0612BC for ; Tue, 8 Feb 2022 13:08:51 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id i14so536844wrc.10 for ; Tue, 08 Feb 2022 13:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4vhsaJLRuFd4cLY+OipxjxgQ9+hkB2eOCoIWIkwzsX4=; b=hSTzBYbk+EsRstvMat5gULyq5OnxonnqMQZDYW4OJ03WdVZriqwshzqAMnR7z6Mxs/ W6MTAgwmuJNCwpePfGNu5wjMP+TCcIEb/7e82sC/9tyzHPsI/T9dN7TU5AUq23/yggHX dBWuat8BzdR3DTzRrJ0Hynpwp08gs8C0OyboY= 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=4vhsaJLRuFd4cLY+OipxjxgQ9+hkB2eOCoIWIkwzsX4=; b=OYg4059kv9HWSXl2b0YONUpqx/XLE+og13GH9Ze56zf7c/sMY0CFwPGF1uvH6oSVzb vg469kDOoozp7TzDgLszSf7PoBLVRwK+P5GT4Ux/JX47AjYRsqjdX+xTlB5MaFvFf/9J zETNtvoMJfMxE4A5fJzVGA7RJFvKDVLGhRJANl1tBKAKy3Xu3uLqEvgBPcsqJEmJdRjf f+BSd7D7wSoY8xEUjMQeSSR3gO0n55EbUpZSH53mgErauuRR38o4dNJNXm7XodLZPNtb he1GRjh4tCcmtEQf5qj2fr9I7ZpfdQ6TiwqK8N9ZWHxwtHuy1pqDYl0cV/4HIW1lz91K x1gw== X-Gm-Message-State: AOAM530lIdjwsAFM436seckKAWrMCRFQ+tG/1ostWHldDqdgZ3RQctPN oaHO7RH+IqBy1KcYehRCU3SLmA== X-Google-Smtp-Source: ABdhPJx34FaRILEJCtAru2c7l4UL1l3tfbLxaWVDlH2pbi+Y5VD+HSoJSIbcO7Y6315RPOWA+MZjag== X-Received: by 2002:a5d:5246:: with SMTP id k6mr4924929wrc.89.1644354530369; Tue, 08 Feb 2022 13:08:50 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:49 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Claudio Suarez , Tetsuo Handa , Thomas Zimmermann , Greg Kroah-Hartman , Du Cheng , Matthew Wilcox , William Kucharski , Alex Deucher , Zheyu Ma , Zhen Lei , Xiyu Yang Subject: [PATCH v2 12/19] fbcon: use lock_fb_info in fbcon_open/release Date: Tue, 8 Feb 2022 22:08:17 +0100 Message-Id: <20220208210824.2238981-13-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Now we get to the real motiviation, because fbmem.c insists that that's the right lock for these. Ofc fbcon.c has a lot more places where it probably should call lock_fb_info(). But looking at fbmem.c at least most of these seem to be protected by console_lock() too, which is probably what papers over any issues. Note that this means we're shuffling around a bit the locking sections for some of the console takeover and unbind paths, but not all: - console binding/unbinding from the console layer never with lock_fb_info - unbind (as opposed to unlink) never bother with lock_fb_info Also the real serialization against set_par and set_pan are still doing by wrapping the entire ioctl code in console_lock(). So this shuffling shouldn't be worse than what we had from a "can you trigger races?" pov, but it's at least clearer. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Claudio Suarez Cc: Tetsuo Handa Cc: Thomas Zimmermann Cc: Greg Kroah-Hartman Cc: Du Cheng Cc: Sam Ravnborg Cc: Matthew Wilcox Cc: William Kucharski Cc: Alex Deucher Cc: Zheyu Ma Cc: Zhen Lei Cc: Xiyu Yang --- drivers/video/fbdev/core/fbcon.c | 5 +++++ drivers/video/fbdev/core/fbmem.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index f0213a0e3870..cc960bf49991 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -684,8 +684,10 @@ static int fbcon_invalid_charcount(struct fb_info *inf= o, unsigned charcount) =20 static void fbcon_release(struct fb_info *info) { + lock_fb_info(info); if (info->fbops->fb_release) info->fbops->fb_release(info, 0); + unlock_fb_info(info); =20 module_put(info->fbops->owner); } @@ -697,11 +699,14 @@ static int fbcon_open(struct fb_info *info) if (!try_module_get(info->fbops->owner)) return -ENODEV; =20 + lock_fb_info(info); if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) { + unlock_fb_info(info); module_put(info->fbops->owner); return -ENODEV; } + unlock_fb_info(info); =20 ops =3D kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); if (!ops) { diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index ad9aac06427a..37656883e7bd 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1674,9 +1674,7 @@ static int do_register_framebuffer(struct fb_info *fb= _info) console_lock(); else atomic_inc(&ignore_console_lock_warning); - lock_fb_info(fb_info); ret =3D fbcon_fb_registered(fb_info); - unlock_fb_info(fb_info); =20 if (!lockless_register_fb) console_unlock(); @@ -1693,9 +1691,7 @@ static void unbind_console(struct fb_info *fb_info) return; =20 console_lock(); - lock_fb_info(fb_info); fbcon_fb_unbind(fb_info); - unlock_fb_info(fb_info); console_unlock(); } =20 --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 CA273C35278 for ; Tue, 8 Feb 2022 22:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386932AbiBHW1h (ORCPT ); Tue, 8 Feb 2022 17:27:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386733AbiBHVIx (ORCPT ); Tue, 8 Feb 2022 16:08:53 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 150F5C0612BA for ; Tue, 8 Feb 2022 13:08:53 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id q7so506724wrc.13 for ; Tue, 08 Feb 2022 13:08:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ox4yXC0LP8o2wCPaioNRgnQjoBr7m6vhS+hT+ChhFWw=; b=S5BqVNPSpXHrqviuw3HJUVHCNuXrwfZETQgddkSqec9Q51qTu/X1Dy3DHTTT/LagCc TdfBUwokFJF0o/5jKLoZI4jM9BwZ4q0H1RYvw+h1/Ibn+wlkQIVyJ99QoReMwJFgFFyb hL6uv3nX42Ve284n0fZhP+uQl2c3CEhq0yFcA= 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=Ox4yXC0LP8o2wCPaioNRgnQjoBr7m6vhS+hT+ChhFWw=; b=Pn57n67Oh4AKJXzwZI/yApHLI1Tw1cEd49FnqdD99PFc/EhIQMv1adjOaEuWUygQ5E 9vixJcaHIdASXl0aqSvLdpnp6da87ZXopRUscMwbkaczlrLQNcrghowSv7WdaZzkhMRc lE2w9jUsgECBXY+2ClNA8TuoEdaSRbtdSF4nhqG3qlE+9UUeYuvxwWbAM3ylGpmistcR CbxfeFctjwo1BIcZL5hr2D8fphRUpeAeMfmg1w26uZSDX0erN93tlisGvZHyW053EMBg K/157KvKq1m1i9JUuJwhIhVLvL04sDHkKh62Hslk3yxzYL8PJYCGMZde96b5fmQnMmj/ EbOA== X-Gm-Message-State: AOAM530tiNzWmA3KRS3Q1mmMgiVZx1/JQV5Br3gyc06oefpmOyMMQFbH DvHl4zGZt6f4+Qe3G4Rre+hwpQ== X-Google-Smtp-Source: ABdhPJz+CmlVndGXlugGb0ahxfiZBUSbHrx3Tg5Zrm6dge27t3XQoa5XtM7kt+nVAKioCX2KEMo9QQ== X-Received: by 2002:a5d:4c41:: with SMTP id n1mr4989076wrt.128.1644354531674; Tue, 08 Feb 2022 13:08:51 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:50 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Du Cheng , Tetsuo Handa , Claudio Suarez , Thomas Zimmermann Subject: [PATCH v2 13/19] fbcon: Consistently protect deferred_takeover with console_lock() Date: Tue, 8 Feb 2022 22:08:18 +0100 Message-Id: <20220208210824.2238981-14-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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 shouldn't be a problem in practice since until we've actually taken over the console there's nothing we've registered with the console/vt subsystem, so the exit/unbind path that check this can't do the wrong thing. But it's confusing, so fix it by moving it a tad later. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Du Cheng Cc: Tetsuo Handa Cc: Claudio Suarez Cc: Thomas Zimmermann --- drivers/video/fbdev/core/fbcon.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index cc960bf49991..4f9752ee9189 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -3227,6 +3227,9 @@ static void fbcon_register_existing_fbs(struct work_s= truct *work) =20 console_lock(); =20 + deferred_takeover =3D false; + logo_shown =3D FBCON_LOGO_DONTSHOW; + for_each_registered_fb(i) fbcon_fb_registered(registered_fb[i]); =20 @@ -3244,8 +3247,6 @@ static int fbcon_output_notifier(struct notifier_bloc= k *nb, pr_info("fbcon: Taking over console\n"); =20 dummycon_unregister_output_notifier(&fbcon_output_nb); - deferred_takeover =3D false; - logo_shown =3D FBCON_LOGO_DONTSHOW; =20 /* We may get called in atomic context */ schedule_work(&fbcon_deferred_takeover_work); --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 62519C433F5 for ; Tue, 8 Feb 2022 22:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387488AbiBHW2J (ORCPT ); Tue, 8 Feb 2022 17:28:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386739AbiBHVIz (ORCPT ); Tue, 8 Feb 2022 16:08:55 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 965A5C0612B8 for ; Tue, 8 Feb 2022 13:08:54 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id e3so674843wra.0 for ; Tue, 08 Feb 2022 13:08:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5dejATrMlEFDMStF3OMugI910D6zgAzmO5LlqrLdpoQ=; b=Vg1y5QTUtQPV6CG6h9MGHsJhE0k2b69Rfhh2j1S9IuenRN1GWwvmFzFJpiuPcQwm9A 8wtN+XoACH3DLsEdXmydVgZh8yHMegVuRM8+2Yff7ryLYiM9OyCcjpUEW/7GTKAx98je TMkLIra5W9DrBamN01sItC1ThQl5ST5R9mGcM= 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=5dejATrMlEFDMStF3OMugI910D6zgAzmO5LlqrLdpoQ=; b=DEG9itv2lLZkFFwdVfQHO9PmDKiSpeiknR2Q5mEY8AEZEZbHfD4W5WmUBP/tPnezHe tXo9ynacF+xgRw2De4go23vsOwMzDLbrh6I2ZNKMPJVitlPYbHzOqh7WovZQJ7wMEiFC TQBCpj5CMD3ttweix5blXLm2kzmBEqdJLG/T/Wih07i4DtjYpcDTkvYxRiHalHIIemNZ 7FVPr749k1/RgLe55elChQBnRx4Va6w4AVxn1cU7PBp8lpffi1HYJvp63CUgC0P9HeN4 2wSgo6SpHavSCWkJ/4oOeFdJESZQhxZSTo2f6Wgwv/UrXB+u1cVhAr9yn3ZuSoU9HsGS tRKQ== X-Gm-Message-State: AOAM53258PTUfnBOsYAT/E12n5c92mCXQ8H274pxSp9UI86gEwwV0LbV q0y1tuubj9FTpmJZP7pPaImYDg== X-Google-Smtp-Source: ABdhPJxnNKHzn5v9jmu/dxkGA2+iLKqES3WUl0y1h3nMtz+C+V7YDVarwK1JvdMEbxQauvwana1kng== X-Received: by 2002:a5d:46c5:: with SMTP id g5mr4776916wrs.406.1644354533075; Tue, 08 Feb 2022 13:08:53 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:52 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Thomas Zimmermann , Du Cheng , Claudio Suarez , Greg Kroah-Hartman , Tetsuo Handa , Matthew Wilcox , Zheyu Ma , Guenter Roeck , Alex Deucher , Zhen Lei , Xiyu Yang Subject: [PATCH v2 14/19] fbcon: Move console_lock for register/unlink/unregister Date: Tue, 8 Feb 2022 22:08:19 +0100 Message-Id: <20220208210824.2238981-15-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Ideally console_lock becomes an implementation detail of fbcon.c and doesn't show up anywhere in fbmem.c. We're still pretty far from that, but at least the register/unregister code is there now. With this the do_fb_ioctl() handler is the only code in fbmem.c still calling console_lock(). Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Du Cheng Cc: Claudio Suarez Cc: Greg Kroah-Hartman Cc: Tetsuo Handa Cc: Matthew Wilcox Cc: Sam Ravnborg Cc: Zheyu Ma Cc: Guenter Roeck Cc: Alex Deucher Cc: Zhen Lei Cc: Xiyu Yang --- drivers/video/fbdev/core/fbcon.c | 33 ++++++++++++++++++++++++++------ drivers/video/fbdev/core/fbmem.c | 23 ++-------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 4f9752ee9189..abb419a091c6 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2756,10 +2756,12 @@ void fbcon_fb_unbind(struct fb_info *info) int i, new_idx =3D -1; int idx =3D info->node; =20 - WARN_CONSOLE_UNLOCKED(); + console_lock(); =20 - if (!fbcon_has_console_bind) + if (!fbcon_has_console_bind) { + console_unlock(); return; + } =20 for (i =3D first_fb_vc; i <=3D last_fb_vc; i++) { if (con2fb_map[i] !=3D idx && @@ -2794,6 +2796,8 @@ void fbcon_fb_unbind(struct fb_info *info) } fbcon_unbind(); } + + console_unlock(); } =20 /* called with console_lock held */ @@ -2801,10 +2805,12 @@ void fbcon_fb_unregistered(struct fb_info *info) { int i, idx; =20 - WARN_CONSOLE_UNLOCKED(); + console_lock(); =20 - if (deferred_takeover) + if (deferred_takeover) { + console_unlock(); return; + } =20 idx =3D info->node; for (i =3D first_fb_vc; i <=3D last_fb_vc; i++) { @@ -2833,6 +2839,7 @@ void fbcon_fb_unregistered(struct fb_info *info) =20 if (!num_registered_fb) do_unregister_con_driver(&fb_con); + console_unlock(); } =20 void fbcon_remap_all(struct fb_info *info) @@ -2890,19 +2897,27 @@ static inline void fbcon_select_primary(struct fb_i= nfo *info) } #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */ =20 +static bool lockless_register_fb; +module_param_named_unsafe(lockless_register_fb, lockless_register_fb, bool= , 0400); +MODULE_PARM_DESC(lockless_register_fb, + "Lockless framebuffer registration for debugging [default=3Doff]"); + /* called with console_lock held */ int fbcon_fb_registered(struct fb_info *info) { int ret =3D 0, i, idx; =20 - WARN_CONSOLE_UNLOCKED(); + if (!lockless_register_fb) + console_lock(); + else + atomic_inc(&ignore_console_lock_warning); =20 idx =3D info->node; fbcon_select_primary(info); =20 if (deferred_takeover) { pr_info("fbcon: Deferring console take-over\n"); - return 0; + goto out; } =20 if (info_idx =3D=3D -1) { @@ -2922,6 +2937,12 @@ int fbcon_fb_registered(struct fb_info *info) } } =20 +out: + if (!lockless_register_fb) + console_unlock(); + else + atomic_dec(&ignore_console_lock_warning); + return ret; } =20 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index 37656883e7bd..6f6f7a763969 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1594,14 +1594,9 @@ static void do_remove_conflicting_framebuffers(struc= t apertures_struct *a, } } =20 -static bool lockless_register_fb; -module_param_named_unsafe(lockless_register_fb, lockless_register_fb, bool= , 0400); -MODULE_PARM_DESC(lockless_register_fb, - "Lockless framebuffer registration for debugging [default=3Doff]"); - static int do_register_framebuffer(struct fb_info *fb_info) { - int i, ret; + int i; struct fb_videomode mode; =20 if (fb_check_foreignness(fb_info)) @@ -1670,17 +1665,7 @@ static int do_register_framebuffer(struct fb_info *f= b_info) } #endif =20 - if (!lockless_register_fb) - console_lock(); - else - atomic_inc(&ignore_console_lock_warning); - ret =3D fbcon_fb_registered(fb_info); - - if (!lockless_register_fb) - console_unlock(); - else - atomic_dec(&ignore_console_lock_warning); - return ret; + return fbcon_fb_registered(fb_info); } =20 static void unbind_console(struct fb_info *fb_info) @@ -1690,9 +1675,7 @@ static void unbind_console(struct fb_info *fb_info) if (WARN_ON(i < 0 || i >=3D FB_MAX || registered_fb[i] !=3D fb_info)) return; =20 - console_lock(); fbcon_fb_unbind(fb_info); - console_unlock(); } =20 static void unlink_framebuffer(struct fb_info *fb_info) @@ -1735,9 +1718,7 @@ static void do_unregister_framebuffer(struct fb_info = *fb_info) fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event); } #endif - console_lock(); fbcon_fb_unregistered(fb_info); - console_unlock(); =20 /* this may free fb info */ put_fb_info(fb_info); --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 7DA33C4332F for ; Tue, 8 Feb 2022 22:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387374AbiBHWXT (ORCPT ); Tue, 8 Feb 2022 17:23:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386743AbiBHVI4 (ORCPT ); Tue, 8 Feb 2022 16:08:56 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7FEEC0612BC for ; Tue, 8 Feb 2022 13:08:55 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id q7so506885wrc.13 for ; Tue, 08 Feb 2022 13:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NR3Vdl26ogLJ+NN6vOMjLgqKjNNnH/ILBJ7SwyK58u4=; b=NngozCg3J7yEp5L8pu/P/IyZeg/re7bovaBC5F+6eL8Vv+gBM4lELsCPvoIG1krc8x fn3vBTkvV/mGVP7Iviya7yAY4SMFa6v06yL2bpIDEOR57CQmP1GIorMKxvW2TfxkB9Fh 5nRE/JTAEFZejtofuDVVxS2+4o5bnY8TkR/2g= 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=NR3Vdl26ogLJ+NN6vOMjLgqKjNNnH/ILBJ7SwyK58u4=; b=eFSxgCYemPeVxWEMbaHvdG7n1//Wus148mS4p2s/dMi5eaSJUiJaSfD0Zl9Wxo7pQB rmWS3QdjQCU5us1f2VXSoMte/+VXdRLGtRZc85lPvAy33tj/8KbqseY9S/janxs+cLiS RXL//l/vBKaFo9OoRI8E9nExK7lrizgSJMFa/c43dHgBBPmkUSCyfiJtZlggOcAvMMNf /cjyIQpsluaWYWYJIQtioqpnMDwBF0Vvggh2+1IwQxK7qlQfrvuwbRd4LVEwIMPgSNOH WCxuFPzyMzxSoI0p6mrhva1danj8QOJk+gR1YsH1W8hYdH3JcNSvHAcLBmOINKl5KWas PZBQ== X-Gm-Message-State: AOAM530g/XI+xFIIOKDtXpCVtOgTB1roeTLUHcw972HLGji/Ecdh9Nv2 hvErBcWJ3Y+fchQxbbsd7r/+/g== X-Google-Smtp-Source: ABdhPJyow1dh1qcgGqJFdixNGVvExdy2/GOvui0v1qlnbPgy6uaK5cpmHHHwHze64OPlU3pcDhqIUA== X-Received: by 2002:adf:a4c8:: with SMTP id h8mr324157wrb.169.1644354534298; Tue, 08 Feb 2022 13:08:54 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:53 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Tetsuo Handa , Greg Kroah-Hartman , Du Cheng , Claudio Suarez Subject: [PATCH v2 15/19] fbcon: Move more code into fbcon_release Date: Tue, 8 Feb 2022 22:08:20 +0100 Message-Id: <20220208210824.2238981-16-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" con2fb_release_oldinfo() has a bunch more kfree() calls than fbcon_exit(), but since kfree() on NULL is harmless doing that in both places should be ok. This is also a bit more symmetric now again with fbcon_open also allocating the fbcon_ops structure. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Tetsuo Handa Cc: Greg Kroah-Hartman Cc: Du Cheng Cc: Claudio Suarez --- drivers/video/fbdev/core/fbcon.c | 33 +++++++++++++------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index abb419a091c6..685b4a9e5546 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -690,6 +690,18 @@ static void fbcon_release(struct fb_info *info) unlock_fb_info(info); =20 module_put(info->fbops->owner); + + if (info->fbcon_par) { + struct fbcon_ops *ops =3D info->fbcon_par; + + fbcon_del_cursor_work(info); + kfree(ops->cursor_state.mask); + kfree(ops->cursor_data); + kfree(ops->cursor_src); + kfree(ops->fontbuffer); + kfree(info->fbcon_par); + info->fbcon_par =3D NULL; + } } =20 static int fbcon_open(struct fb_info *info) @@ -740,18 +752,10 @@ static int con2fb_acquire_newinfo(struct vc_data *vc,= struct fb_info *info, static void con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *old= info, struct fb_info *newinfo) { - struct fbcon_ops *ops =3D oldinfo->fbcon_par; int ret; =20 fbcon_release(oldinfo); =20 - fbcon_del_cursor_work(oldinfo); - kfree(ops->cursor_state.mask); - kfree(ops->cursor_data); - kfree(ops->cursor_src); - kfree(ops->fontbuffer); - kfree(oldinfo->fbcon_par); - oldinfo->fbcon_par =3D NULL; /* If oldinfo and newinfo are driving the same hardware, the fb_release() method of oldinfo may attempt to @@ -3315,19 +3319,8 @@ static void fbcon_exit(void) } } =20 - if (mapped) { - if (info->fbcon_par) { - struct fbcon_ops *ops =3D info->fbcon_par; - - fbcon_del_cursor_work(info); - kfree(ops->cursor_src); - kfree(ops->cursor_state.mask); - kfree(info->fbcon_par); - info->fbcon_par =3D NULL; - } - + if (mapped) fbcon_release(info); - } } } =20 --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 7C53DC35275 for ; Tue, 8 Feb 2022 22:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387519AbiBHWYV (ORCPT ); Tue, 8 Feb 2022 17:24:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386752AbiBHVI5 (ORCPT ); Tue, 8 Feb 2022 16:08:57 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3587C0612B8 for ; Tue, 8 Feb 2022 13:08:56 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id e3so674979wra.0 for ; Tue, 08 Feb 2022 13:08:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PCYS5QyMNkkwqTDkShTEbfPtwnFmBXM7JP7Pazg2YKM=; b=kTDETVVLcYRtMjjA8LySpUTc6zRE3ZqOVKlYdUkFPag87WIkrPWX47b+Rb5Gehv3cR LO/YoTPo1B1XpGaBAzdpwQ20SF/lTTiXX0i09lBUwufoAO3uAsw/1GqRYGbBpFouLnMs kFt72PsgGfZ5DstDIs4E5PvzoMLE0yCbrB9+Y= 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=PCYS5QyMNkkwqTDkShTEbfPtwnFmBXM7JP7Pazg2YKM=; b=UiaBsv7Zdacwd+iLkCdYRZ34V/ZjyG7Zlw9iSXU2ah/QajBJj4jd9S9BbDmtiHPVcO +AhkCFW85K/Ur9zcixG860yDPI1Xt+Edns46BP6ELomsM+dv7eljhNbjkTuNNSEMlAf+ tHGRaLyaSovHYzRZLKMctLfJcWHOyZW9R52NzVS0L00GcJUfUEiZewW2xuzreksmGSvE hEC3znwXod9lZ/q4o1EmBc5AQI3piYkqEH5ogEyrY8jdhKWsQSH+o8/2xSQKzdPSdqd8 g5p/k//JRuJo85+mfOa4cFjSGPtkPoELaEzrvM+CV7FjuzXyNfmfrOh15MedGKnAsX5k dYew== X-Gm-Message-State: AOAM531FG0PMK1bQu9FIGpoSBjTUnFBuLU7P7Rr+JbZqYPMZDsOupn36 hWRuDqoglISTazkWUa7RCbFECw== X-Google-Smtp-Source: ABdhPJzoozBk4sCtvPwFCt7Ns2n0EIlD3c2Oag8W2C4RKf4YDquTma29XshfY3LkS6cE7lgaMjCoTA== X-Received: by 2002:adf:fe01:: with SMTP id n1mr5008752wrr.141.1644354535375; Tue, 08 Feb 2022 13:08:55 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:54 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Greg Kroah-Hartman , Claudio Suarez , Du Cheng , Tetsuo Handa Subject: [PATCH v2 16/19] fbcon: untangle fbcon_exit Date: Tue, 8 Feb 2022 22:08:21 +0100 Message-Id: <20220208210824.2238981-17-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" There's a bunch of confusions going on here: - The deferred fbcon setup notifier should only be cleaned up from fb_console_exit(), to be symmetric with fb_console_init() - We also need to make sure we don't race with the work, which means temporarily dropping the console lock (or we can deadlock) - That also means no point in clearing deferred_takeover, we are unloading everything anyway. - Finally rename fbcon_exit to fbcon_release_all and move it, since that's what's it doing when being called from consw->con_deinit through fbcon_deinit. To answer a question from Sam just quoting my own reply: > We loose the call to fbcon_release_all() here [in fb_console_exit()]. > We have part of the old fbcon_exit() above, but miss the release parts. Ah yes that's the entire point of this change. The release_all in the fbcon exit path was only needed when fbcon was a separate module indepedent from core fb.ko. Which means it was possible to unload fbcon while having fbdev drivers registered. But since we've merged them that has become impossible, so by the time the fb.ko module can be unloaded, there's guaranteed to be no fbdev drivers left. And hence removing them is pointless. v2: Explain the why better (Sam) Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Greg Kroah-Hartman Cc: Claudio Suarez Cc: Du Cheng Cc: Tetsuo Handa --- drivers/video/fbdev/core/fbcon.c | 63 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 685b4a9e5546..944f514c77ec 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -187,7 +187,6 @@ static void fbcon_redraw_move(struct vc_data *vc, struc= t fbcon_display *p, int line, int count, int dy); static void fbcon_modechanged(struct fb_info *info); static void fbcon_set_all_vcs(struct fb_info *info); -static void fbcon_exit(void); =20 static struct device *fbcon_device; =20 @@ -1146,6 +1145,27 @@ static void fbcon_free_font(struct fbcon_display *p,= bool freefont) =20 static void set_vc_hi_font(struct vc_data *vc, bool set); =20 +static void fbcon_release_all(void) +{ + struct fb_info *info; + int i, j, mapped; + + for_each_registered_fb(i) { + mapped =3D 0; + info =3D registered_fb[i]; + + for (j =3D first_fb_vc; j <=3D last_fb_vc; j++) { + if (con2fb_map[j] =3D=3D i) { + mapped =3D 1; + con2fb_map[j] =3D -1; + } + } + + if (mapped) + fbcon_release(info); + } +} + static void fbcon_deinit(struct vc_data *vc) { struct fbcon_display *p =3D &fb_display[vc->vc_num]; @@ -1185,7 +1205,7 @@ static void fbcon_deinit(struct vc_data *vc) set_vc_hi_font(vc, false); =20 if (!con_is_bound(&fb_con)) - fbcon_exit(); + fbcon_release_all(); =20 if (vc->vc_num =3D=3D logo_shown) logo_shown =3D FBCON_LOGO_CANSHOW; @@ -3296,34 +3316,6 @@ static void fbcon_start(void) #endif } =20 -static void fbcon_exit(void) -{ - struct fb_info *info; - int i, j, mapped; - -#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER - if (deferred_takeover) { - dummycon_unregister_output_notifier(&fbcon_output_nb); - deferred_takeover =3D false; - } -#endif - - for_each_registered_fb(i) { - mapped =3D 0; - info =3D registered_fb[i]; - - for (j =3D first_fb_vc; j <=3D last_fb_vc; j++) { - if (con2fb_map[j] =3D=3D i) { - mapped =3D 1; - con2fb_map[j] =3D -1; - } - } - - if (mapped) - fbcon_release(info); - } -} - void __init fb_console_init(void) { int i; @@ -3363,10 +3355,19 @@ static void __exit fbcon_deinit_device(void) =20 void __exit fb_console_exit(void) { +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER + console_lock(); + if (deferred_takeover) + dummycon_unregister_output_notifier(&fbcon_output_nb); + console_unlock(); + + cancel_work_sync(&fbcon_deferred_takeover_work); +#endif + console_lock(); fbcon_deinit_device(); device_destroy(fb_class, MKDEV(0, 0)); - fbcon_exit(); + do_unregister_con_driver(&fb_con); console_unlock(); }=09 --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 0DB1BC433FE for ; Tue, 8 Feb 2022 22:39:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386786AbiBHWej (ORCPT ); Tue, 8 Feb 2022 17:34:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386757AbiBHVI6 (ORCPT ); Tue, 8 Feb 2022 16:08:58 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC560C0612BC for ; Tue, 8 Feb 2022 13:08:57 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id i15so609958wrb.3 for ; Tue, 08 Feb 2022 13:08:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NyPCuPft4VaB2bVEt8jlMDRi9/YFFe0dNdOhzBh/pVo=; b=aawQdusFo5feJFuhXzMoJ49/qU8d+ooMce0HpRYoXBt6yGf3ijYr7CGMbFThwkAH1V p7p3m9MoCSYTyxYMHncWQPSc2adNdGMnIypoEoWJVsnR6Q/7IQrQzM8mdvGkU7qRXNIC MzBRQNoXHcMWnacdpVF7H7ZR/Vyi5dt6k9tmg= 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=NyPCuPft4VaB2bVEt8jlMDRi9/YFFe0dNdOhzBh/pVo=; b=V6YEaPUtIZ/DAsNnYDauaZWOLpYjiFvdNd+f0yB13shxqJPZjRMQq3/qNdkjCMlMEq Exf9OMsal4qtrwTEjvbyuhStJCtQyRiPaDSB1Jc5IsNE5NykwYMEw38vf9gaaF4LPkFm JLmv1Za+Wer3ANS3UXcs7bmUcQQlv3VUeTDchOXKzMePWBDN6k0v5r1KG5TFqOiwFFnN tG7s04zBVRrWj/gxU/RRwtoX7SQrr50KHEmwsdxy9oTA9XehzW2bMrhGAdaJeMq9XYLz PB6VYB+pWIQMMQReIAdd7ydyQDcLcVl6HQDRSQDNTWOgwBHpUHwQ+C8FmAWq3UfLGGKM KsjQ== X-Gm-Message-State: AOAM532iI3dj2fpRTYJST7PcUiq8Lbclrh/QJROxA0mjh6wYkYwwwgmq peDJP5q88j0Eshq8Sev5CO6wmw== X-Google-Smtp-Source: ABdhPJyA7a0WtGiKEc9Hx0Id9CYQn2eyAOKKOMDLXoycCrXIIKxBobqiCvwcQ1tmmiyztoyt/Hxazg== X-Received: by 2002:adf:f504:: with SMTP id q4mr1972172wro.670.1644354536398; Tue, 08 Feb 2022 13:08:56 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:55 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Sam Ravnborg , Daniel Vetter , Daniel Vetter , Tetsuo Handa , Claudio Suarez , Du Cheng , Greg Kroah-Hartman Subject: [PATCH v2 17/19] fbcon: Maintain a private array of fb_info Date: Tue, 8 Feb 2022 22:08:22 +0100 Message-Id: <20220208210824.2238981-18-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Accessing the one in fbmem.c without taking the right locks is a bad idea. Instead maintain our own private copy, which is fully protected by console_lock() (like everything else in fbcon.c). That copy is serialized through fbcon_fb_registered/unregistered() calls. Also this means we do not need to hold a full fb_info reference, which is nice because doing so would mean a refcount loop between the console and the fb_info. But it's also not nice since it means console_lock() must be held absolutely everywhere. Well strictly speaking we could still try to do some refcounting games again by calling get_fb_info before we drop the console_lock. But things will get tricky. Acked-by: Sam Ravnborg Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Tetsuo Handa Cc: Claudio Suarez Cc: Du Cheng Cc: Greg Kroah-Hartman --- drivers/video/fbdev/core/fbcon.c | 82 +++++++++++++++++--------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fb= con.c index 944f514c77ec..6a7d470beec7 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -86,10 +86,6 @@ * - fbcon state itself is protected by the console_lock, and the code doe= s a * pretty good job at making sure that lock is held everywhere it's need= ed. * - * - access to the registered_fb array is entirely unprotected. This shoul= d use - * proper object lifetime handling, i.e. get/put_fb_info. This also means - * switching from indices to proper pointers for fb_info everywhere. - * * - fbcon doesn't bother with fb_lock/unlock at all. This is buggy, since= it * means concurrent access to the same fbdev from both fbcon and userspa= ce * will blow up. To fix this all fbcon calls from fbmem.c need to be mov= ed out @@ -107,6 +103,13 @@ enum { =20 static struct fbcon_display fb_display[MAX_NR_CONSOLES]; =20 +struct fb_info *fbcon_registered_fb[FB_MAX]; +int fbcon_num_registered_fb; + +#define fbcon_for_each_registered_fb(i) \ + for (i =3D 0; WARN_CONSOLE_UNLOCKED(), i < FB_MAX; i++) \ + if (!fbcon_registered_fb[i]) {} else + static signed char con2fb_map[MAX_NR_CONSOLES]; static signed char con2fb_map_boot[MAX_NR_CONSOLES]; =20 @@ -114,12 +117,7 @@ static struct fb_info *fbcon_info_from_console(int con= sole) { WARN_CONSOLE_UNLOCKED(); =20 - /* - * Note that only con2fb_map is protected by the console lock, - * registered_fb is protected by a separate mutex. This lookup can - * therefore race. - */ - return registered_fb[con2fb_map[console]]; + return fbcon_registered_fb[con2fb_map[console]]; } =20 static int logo_lines; @@ -518,7 +516,7 @@ static int do_fbcon_takeover(int show_logo) { int err, i; =20 - if (!num_registered_fb) + if (!fbcon_num_registered_fb) return -ENODEV; =20 if (!show_logo) @@ -821,7 +819,7 @@ static int set_con2fb_map(int unit, int newidx, int use= r) { struct vc_data *vc =3D vc_cons[unit].d; int oldidx =3D con2fb_map[unit]; - struct fb_info *info =3D registered_fb[newidx]; + struct fb_info *info =3D fbcon_registered_fb[newidx]; struct fb_info *oldinfo =3D NULL; int found, err =3D 0, show_logo; =20 @@ -839,7 +837,7 @@ static int set_con2fb_map(int unit, int newidx, int use= r) } =20 if (oldidx !=3D -1) - oldinfo =3D registered_fb[oldidx]; + oldinfo =3D fbcon_registered_fb[oldidx]; =20 found =3D search_fb_in_map(newidx); =20 @@ -931,13 +929,13 @@ static const char *fbcon_startup(void) * If num_registered_fb is zero, this is a call for the dummy part. * The frame buffer devices weren't initialized yet. */ - if (!num_registered_fb || info_idx =3D=3D -1) + if (!fbcon_num_registered_fb || info_idx =3D=3D -1) return display_desc; /* * Instead of blindly using registered_fb[0], we use info_idx, set by * fbcon_fb_registered(); */ - info =3D registered_fb[info_idx]; + info =3D fbcon_registered_fb[info_idx]; if (!info) return NULL; =09 @@ -1150,9 +1148,9 @@ static void fbcon_release_all(void) struct fb_info *info; int i, j, mapped; =20 - for_each_registered_fb(i) { + fbcon_for_each_registered_fb(i) { mapped =3D 0; - info =3D registered_fb[i]; + info =3D fbcon_registered_fb[i]; =20 for (j =3D first_fb_vc; j <=3D last_fb_vc; j++) { if (con2fb_map[j] =3D=3D i) { @@ -1179,7 +1177,7 @@ static void fbcon_deinit(struct vc_data *vc) if (idx =3D=3D -1) goto finished; =20 - info =3D registered_fb[idx]; + info =3D fbcon_registered_fb[idx]; =20 if (!info) goto finished; @@ -2098,9 +2096,9 @@ static int fbcon_switch(struct vc_data *vc) * * info->currcon =3D vc->vc_num; */ - for_each_registered_fb(i) { - if (registered_fb[i]->fbcon_par) { - struct fbcon_ops *o =3D registered_fb[i]->fbcon_par; + fbcon_for_each_registered_fb(i) { + if (fbcon_registered_fb[i]->fbcon_par) { + struct fbcon_ops *o =3D fbcon_registered_fb[i]->fbcon_par; =20 o->currcon =3D vc->vc_num; } @@ -2745,7 +2743,7 @@ int fbcon_mode_deleted(struct fb_info *info, j =3D con2fb_map[i]; if (j =3D=3D -1) continue; - fb_info =3D registered_fb[j]; + fb_info =3D fbcon_registered_fb[j]; if (fb_info !=3D info) continue; p =3D &fb_display[i]; @@ -2801,7 +2799,7 @@ void fbcon_fb_unbind(struct fb_info *info) set_con2fb_map(i, new_idx, 0); } } else { - struct fb_info *info =3D registered_fb[idx]; + struct fb_info *info =3D fbcon_registered_fb[idx]; =20 /* This is sort of like set_con2fb_map, except it maps * the consoles to no device and then releases the @@ -2831,6 +2829,9 @@ void fbcon_fb_unregistered(struct fb_info *info) =20 console_lock(); =20 + fbcon_registered_fb[info->node] =3D NULL; + fbcon_num_registered_fb--; + if (deferred_takeover) { console_unlock(); return; @@ -2845,7 +2846,7 @@ void fbcon_fb_unregistered(struct fb_info *info) if (idx =3D=3D info_idx) { info_idx =3D -1; =20 - for_each_registered_fb(i) { + fbcon_for_each_registered_fb(i) { info_idx =3D i; break; } @@ -2861,7 +2862,7 @@ void fbcon_fb_unregistered(struct fb_info *info) if (primary_device =3D=3D idx) primary_device =3D -1; =20 - if (!num_registered_fb) + if (!fbcon_num_registered_fb) do_unregister_con_driver(&fb_con); console_unlock(); } @@ -2936,6 +2937,9 @@ int fbcon_fb_registered(struct fb_info *info) else atomic_inc(&ignore_console_lock_warning); =20 + fbcon_registered_fb[info->node] =3D info; + fbcon_num_registered_fb++; + idx =3D info->node; fbcon_select_primary(info); =20 @@ -3055,9 +3059,9 @@ int fbcon_set_con2fb_map_ioctl(void __user *argp) return -EINVAL; if (con2fb.framebuffer >=3D FB_MAX) return -EINVAL; - if (!registered_fb[con2fb.framebuffer]) + if (!fbcon_registered_fb[con2fb.framebuffer]) request_module("fb%d", con2fb.framebuffer); - if (!registered_fb[con2fb.framebuffer]) { + if (!fbcon_registered_fb[con2fb.framebuffer]) { return -EINVAL; } =20 @@ -3124,10 +3128,10 @@ static ssize_t store_rotate(struct device *device, console_lock(); idx =3D con2fb_map[fg_console]; =20 - if (idx =3D=3D -1 || registered_fb[idx] =3D=3D NULL) + if (idx =3D=3D -1 || fbcon_registered_fb[idx] =3D=3D NULL) goto err; =20 - info =3D registered_fb[idx]; + info =3D fbcon_registered_fb[idx]; rotate =3D simple_strtoul(buf, last, 0); fbcon_rotate(info, rotate); err: @@ -3146,10 +3150,10 @@ static ssize_t store_rotate_all(struct device *devi= ce, console_lock(); idx =3D con2fb_map[fg_console]; =20 - if (idx =3D=3D -1 || registered_fb[idx] =3D=3D NULL) + if (idx =3D=3D -1 || fbcon_registered_fb[idx] =3D=3D NULL) goto err; =20 - info =3D registered_fb[idx]; + info =3D fbcon_registered_fb[idx]; rotate =3D simple_strtoul(buf, last, 0); fbcon_rotate_all(info, rotate); err: @@ -3166,10 +3170,10 @@ static ssize_t show_rotate(struct device *device, console_lock(); idx =3D con2fb_map[fg_console]; =20 - if (idx =3D=3D -1 || registered_fb[idx] =3D=3D NULL) + if (idx =3D=3D -1 || fbcon_registered_fb[idx] =3D=3D NULL) goto err; =20 - info =3D registered_fb[idx]; + info =3D fbcon_registered_fb[idx]; rotate =3D fbcon_get_rotate(info); err: console_unlock(); @@ -3186,10 +3190,10 @@ static ssize_t show_cursor_blink(struct device *dev= ice, console_lock(); idx =3D con2fb_map[fg_console]; =20 - if (idx =3D=3D -1 || registered_fb[idx] =3D=3D NULL) + if (idx =3D=3D -1 || fbcon_registered_fb[idx] =3D=3D NULL) goto err; =20 - info =3D registered_fb[idx]; + info =3D fbcon_registered_fb[idx]; ops =3D info->fbcon_par; =20 if (!ops) @@ -3212,10 +3216,10 @@ static ssize_t store_cursor_blink(struct device *de= vice, console_lock(); idx =3D con2fb_map[fg_console]; =20 - if (idx =3D=3D -1 || registered_fb[idx] =3D=3D NULL) + if (idx =3D=3D -1 || fbcon_registered_fb[idx] =3D=3D NULL) goto err; =20 - info =3D registered_fb[idx]; + info =3D fbcon_registered_fb[idx]; =20 if (!info->fbcon_par) goto err; @@ -3275,8 +3279,8 @@ static void fbcon_register_existing_fbs(struct work_s= truct *work) deferred_takeover =3D false; logo_shown =3D FBCON_LOGO_DONTSHOW; =20 - for_each_registered_fb(i) - fbcon_fb_registered(registered_fb[i]); + fbcon_for_each_registered_fb(i) + fbcon_fb_registered(fbcon_registered_fb[i]); =20 console_unlock(); } --=20 2.34.1 From nobody Sun Jun 28 10:36:33 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 20333C35270 for ; Tue, 8 Feb 2022 22:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387434AbiBHW1u (ORCPT ); Tue, 8 Feb 2022 17:27:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386759AbiBHVI7 (ORCPT ); Tue, 8 Feb 2022 16:08:59 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4F8AC0612B8 for ; Tue, 8 Feb 2022 13:08:58 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id v12so616650wrv.2 for ; Tue, 08 Feb 2022 13:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rydNRJgI2Eov1WWIN57pE5aUhiOSvoU+VTOBFAHrkb4=; b=F+hzmxnzOc+718goX4Cs58QWOUfTIDiKrkUB1v+ufkg3+6n7DOvGRg91mu8FfXCAMf FGj9W8B++N5wBz1YYmQT7i0CVcluacCT4V2Jc/ZISCEMgByjOv4cyK77LyJT/v7Slbjx Q/yRK4s31cta8TArkXSJ37qhNy2sB4V2Oyxa8= 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=rydNRJgI2Eov1WWIN57pE5aUhiOSvoU+VTOBFAHrkb4=; b=HGmVobRA0HujRp+Vd21hDLrLXoile+skXUHzHrKaFwZZMwr5N1+VXP/l5f3o1mqIl4 0mjfBZnKgn0B5GzyJv5AaDnDNn17LpA/zb1CMxPf29u4E9FamG4D6NtEz5p2rk+GrL10 sIgIHAN+NuGs5/ZCDZd+HhewoYx92/fYavZ32MYR90mjYc0jBckob2PHOis8NOrL7FGv 5XGGJzJ/QQ3tu2nOoepwyXT+1c3sgbPy+05t3byr87UDqevZzpNXuNctoMGoXAxDsPyD b0c8cspL8Xoqk5w2ypmQnGfbSmvoHfavtVSILjyYQf8Ia74nXna8c2YPD54gpSC9VUr1 WQQw== X-Gm-Message-State: AOAM531pTHPZVfYghrsjuGJ10YwOnWC27sfOprPRfulog+6aYTclR6vJ IK/eOKKkDyEoYV67VcEdX9t/8jrDAHzNEQ== X-Google-Smtp-Source: ABdhPJzxKjz/b2hfgAxYxrOdvg7rGwL2KTseqSZXjP4oQ90LBl4N2T/XH7Zn2NUo7poLdZ1hEUURuQ== X-Received: by 2002:a5d:6da8:: with SMTP id u8mr5135544wrs.362.1644354537326; Tue, 08 Feb 2022 13:08:57 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:56 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , Thomas Zimmermann , Zack Rusin , Javier Martinez Canillas , Hans de Goede , Ilya Trukhanov , Daniel Vetter , Peter Jones Subject: [PATCH v2 18/19] Revert "fbdev: Prevent probing generic drivers if a FB is already registered" Date: Tue, 8 Feb 2022 22:08:23 +0100 Message-Id: <20220208210824.2238981-19-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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 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 --- 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.34.1 From nobody Sun Jun 28 10:36:33 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 A7424C4707F for ; Tue, 8 Feb 2022 22:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388394AbiBHWcs (ORCPT ); Tue, 8 Feb 2022 17:32:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386761AbiBHVJB (ORCPT ); Tue, 8 Feb 2022 16:09:01 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E272CC0612BA for ; Tue, 8 Feb 2022 13:08:59 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id s10so591985wra.5 for ; Tue, 08 Feb 2022 13:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4RkUIVbtXWLMhEgVRprjRhLI7qLO2cMyCi+EhjvzZFw=; b=hTk5ijDHDMgQxKkA9BUrH0F2len3i2uKxb473Xdpw5iK2wSxC9XmwvSbp7bYW0PLPk QbKh5k1BSr/Tz0jA06DfQZya1UO90srY53nLsu9F38wakMDiTM36Bhv99fd2QZrbuYGF DdQESgBxjgKfPc9w3F9JFaETCMViCRldl1gyk= 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=4RkUIVbtXWLMhEgVRprjRhLI7qLO2cMyCi+EhjvzZFw=; b=sTE7lEPAJDIwnYV3XDbOy/1Jpc17/xIE0Avl6gGv0EwGdfED9sh00K+Y2W4Id7xXKV 8Z93lp9s/hQwoPKxgCCWLkZLaxy8X55xwV4HCyUw9CEh9VlFKU6JJwNle3Jv0Yj8XUHc 57JXFTzyV/xQjPnUHsnKmOk659oev1Pu4vf1X0nHOmoP7/JDsucU2bMY9bZqPs1ltYwT sqGZQi8pO0AEUslwBjhm544RIzGfncjkT4I/jwGOEfIfdwNc6OWCJnkgxnjJ9MbhZuF6 cR9GQ6mnHATuu2nSs7FQXxgsfYqpoUdXS/rYnS/fTKAjDhtAUSW/OELYpqhqDMsw3A6e A+CA== X-Gm-Message-State: AOAM532GwZX4Kryph144/mWE7QBcdQ/aElVUfwE+DijyhdYSQuMutP6o PO4LLnpFCA8krKi5raYvdAb0BQ== X-Google-Smtp-Source: ABdhPJyIfpRc7ZB9NjqbdIphlUwlwXNT2L6vdvwdr3OEGArxXf4a6YivXer2aDFvbp3CRI9pZL06XA== X-Received: by 2002:a5d:47af:: with SMTP id 15mr5049471wrb.88.1644354538519; Tue, 08 Feb 2022 13:08:58 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o14sm3033561wmr.3.2022.02.08.13.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 13:08:58 -0800 (PST) From: Daniel Vetter To: DRI Development Cc: Intel Graphics Development , linux-fbdev@vger.kernel.org, LKML , Daniel Vetter , kernel test robot , Jens Frederich , Jon Nettleton , Greg Kroah-Hartman , linux-staging@lists.linux.dev, Daniel Vetter , Daniel Vetter , Helge Deller , Matthew Wilcox , Sam Ravnborg , Tetsuo Handa , Zhen Lei , Alex Deucher , Xiyu Yang , Zheyu Ma , Guenter Roeck Subject: [PATCH v2 19/19] fbdev: Make registered_fb[] private to fbmem.c Date: Tue, 8 Feb 2022 22:08:24 +0100 Message-Id: <20220208210824.2238981-20-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> 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" Well except when the olpc dcon fbdev driver is enabled, that thing digs around in there in rather unfixable ways. Cc oldc_dcon maintainers as fyi. v2: I typoed the config name (0day) Cc: kernel test robot Cc: Jens Frederich Cc: Jon Nettleton Cc: Greg Kroah-Hartman Cc: linux-staging@lists.linux.dev Signed-off-by: Daniel Vetter Cc: Daniel Vetter Cc: Helge Deller Cc: Matthew Wilcox Cc: Sam Ravnborg Cc: Tetsuo Handa Cc: Zhen Lei Cc: Alex Deucher Cc: Xiyu Yang Cc: linux-fbdev@vger.kernel.org Cc: Zheyu Ma Cc: Guenter Roeck --- drivers/video/fbdev/core/fbmem.c | 8 ++++++-- include/linux/fb.h | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index 6f6f7a763969..6f0eb596a2cd 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -49,10 +49,14 @@ static DEFINE_MUTEX(registration_lock); =20 struct fb_info *registered_fb[FB_MAX] __read_mostly; -EXPORT_SYMBOL(registered_fb); - int num_registered_fb __read_mostly; +#if IS_ENABLED(CONFIG_FB_OLPC_DCON) +EXPORT_SYMBOL(registered_fb); EXPORT_SYMBOL(num_registered_fb); +#endif +#define for_each_registered_fb(i) \ + for (i =3D 0; i < FB_MAX; i++) \ + if (!registered_fb[i]) {} else =20 bool fb_center_logo __read_mostly; =20 diff --git a/include/linux/fb.h b/include/linux/fb.h index 23b19cf8bccd..afaa1474a283 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -623,16 +623,15 @@ extern int fb_get_color_depth(struct fb_var_screeninf= o *var, extern int fb_get_options(const char *name, char **option); extern int fb_new_modelist(struct fb_info *info); =20 +#if IS_ENABLED(CONFIG_FB_OLPC_DCON) extern struct fb_info *registered_fb[FB_MAX]; + extern int num_registered_fb; +#endif extern bool fb_center_logo; extern int fb_logo_count; extern struct class *fb_class; =20 -#define for_each_registered_fb(i) \ - for (i =3D 0; i < FB_MAX; i++) \ - if (!registered_fb[i]) {} else - static inline void lock_fb_info(struct fb_info *info) { mutex_lock(&info->lock); --=20 2.34.1