Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp549641pxb; Tue, 5 Apr 2022 13:42:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzG/knKkmxRblUSTEKxZlLuwAXTtt9iBRbDBTPVApOrGVJTOe64lVFcHIduql20hwKTUUHz X-Received: by 2002:a17:90a:4e08:b0:1ca:7108:439e with SMTP id n8-20020a17090a4e0800b001ca7108439emr6161871pjh.27.1649191337314; Tue, 05 Apr 2022 13:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649191337; cv=none; d=google.com; s=arc-20160816; b=Dq7MLhgF5dzprro7YXkEKEw+qkLANcnEVKLlq1CQH7Ag9d3kIsKR3Fmwzhlw41jCq0 nJlCZkIOhSNremApdBWscYAPKjaT/+P7rNFhFNw151yFFCY3UeuMZR4vP3X9mZzoaiwU hqpFcTQY6TXHF343cE7AGL19YxVvmMemsI8TyRd9JQ05tYpBeFKta2oHhknoxqlXJvq6 93US2YjmU/B9gOY8VM1IMIs4ab+5l1Mo1FxlH4wxF66RQawI1FjkzXzeepcKcLO1w/yj 7URkanCocBcGxiorDXR8qISBl7M/eJVZD7lb+qgk3SOYWhMXorY54cG3V5vXac480YNz ntyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=kLwOSJh4JkUAu8bAVMQPem4swoCfWHajhhsSaSbd3wA=; b=Ald9E4Zq0ycBtH9+EoIcL3nRxdZqFr2R+Y3sP/UYPF49RlZWOlogu7vpoR9gOjiI/b anI5kGQeb8KHudaSpCaR7LPP+xt7IdEzeg1RKcv3LGfQwUO7E3MxSPjVjapw4ZPGtuAK c4Rix/on47St0I1adspbKvWfojRZfA7ccG0CEdkIphVE5GZ8jhGkTRQ+BCSa2arkX8w2 IMrjJfJV/EOyGNulaq8NCLVywqv3qNas+GHot/SZggx0Nud0N/Opz7T7jZ/OP5dm5xe2 fDmCLxaumBAVtHSvpyNjAMhNZf4+6KeUuBeqxbNIYIB2fo8DnVzMI40Vyy5GAyjO3h60 THWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=bMbT3uGp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d6-20020a170903230600b00153b2d16520si14434629plh.296.2022.04.05.13.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 13:42:17 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=bMbT3uGp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB1C27804B; Tue, 5 Apr 2022 13:34:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382494AbiDEMPf (ORCPT + 99 others); Tue, 5 Apr 2022 08:15:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244903AbiDEIwq (ORCPT ); Tue, 5 Apr 2022 04:52:46 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFA8F2458C for ; Tue, 5 Apr 2022 01:45:56 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id k23so21738070ejd.3 for ; Tue, 05 Apr 2022 01:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=kLwOSJh4JkUAu8bAVMQPem4swoCfWHajhhsSaSbd3wA=; b=bMbT3uGp3dFxXv5749rP/YEH0fwf2ipBnL4qQcoZffJmqP63odGiG48c6lrEQDoOuE 2Io2E+FIcefJqaP5UzCFcWumnT1yERlYhCUDpyrunp/zi7DwDGmp9jA4EjrBmXZPUbxe m4RBFNb29e21bIjfvB3+04nX0j65o9B8vbaPY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=kLwOSJh4JkUAu8bAVMQPem4swoCfWHajhhsSaSbd3wA=; b=jrJ4CRoGI/THTp1O8nP+KhfA/x0Rq4eGzJ8+2w93iKRLFo1RdGt80MRBKGCKN+XCuB QuAdTKtFLT6GcFEK2/1nS8W71I30QuDj8dLcSLMPC0NzzWV1nM95iJHyXI7dr8NYNnVf OsHPq55PugaGHbiCGWsFGcgd6jo9cUbKYjw4R01i/uWMpMdIZ4xBXRyBDXStSPF8OfqW IBw2dS3yzybVZhAb+Gbd2HJqSy67DdtColzZ4puVnBbvGYvM7hYe1Xj9pqGImTbYMC7U j7mSsnmXoziwWYQtxM4ISB+PhQsdHbNvh223gfIQPiVkAruNgrYGGD6H/EG8vTheYjJF Fm0g== X-Gm-Message-State: AOAM5318AcDWbFwD0FjZd8goDH66jKg2MTOTG7HoQMZXE9qkDxr60ApL TUe5Kxn8+oXAGD9FqSjkJrbrqQ== X-Received: by 2002:a17:906:300f:b0:6e0:b38d:777d with SMTP id 15-20020a170906300f00b006e0b38d777dmr2418845ejz.189.1649148355361; Tue, 05 Apr 2022 01:45:55 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id a22-20020a50ff16000000b00410d029ea5csm6312065edu.96.2022.04.05.01.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 01:45:54 -0700 (PDT) Date: Tue, 5 Apr 2022 10:45:53 +0200 From: Daniel Vetter To: Thomas Zimmermann Cc: Daniel Vetter , DRI Development , linux-fbdev@vger.kernel.org, Du Cheng , Tetsuo Handa , Intel Graphics Development , LKML , Claudio Suarez , Greg Kroah-Hartman , Daniel Vetter , Sam Ravnborg Subject: Re: [PATCH v2 09/19] fbcon: Extract fbcon_open/release helpers Message-ID: Mail-Followup-To: Thomas Zimmermann , DRI Development , linux-fbdev@vger.kernel.org, Du Cheng , Tetsuo Handa , Intel Graphics Development , LKML , Claudio Suarez , Greg Kroah-Hartman , Daniel Vetter , Sam Ravnborg References: <20220208210824.2238981-1-daniel.vetter@ffwll.ch> <20220208210824.2238981-10-daniel.vetter@ffwll.ch> <0879a2ff-37df-a9ae-0ce1-2bfcb2d1b322@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0879a2ff-37df-a9ae-0ce1-2bfcb2d1b322@suse.de> X-Operating-System: Linux phenom 5.10.0-8-amd64 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 10, 2022 at 12:46:32PM +0100, Thomas Zimmermann wrote: > Hi > > Am 08.02.22 um 22:08 schrieb Daniel Vetter: > > 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/fbcon.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 *info, unsigned charcount) > > #endif /* CONFIG_MISC_TILEBLITTING */ > > +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); > > +} > > static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info, > > int unit, int oldidx) > > { > > struct fbcon_ops *ops = NULL; > > - int err = 0; > > - > > - if (!try_module_get(info->fbops->owner)) > > - err = -ENODEV; > > + int err; > > - if (!err && info->fbops->fb_open && > > - info->fbops->fb_open(info, 0)) > > - err = -ENODEV; > > + err = fbcon_open(info); > > + if (err) > > + return err; > > if (!err) { > > ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); > > @@ -715,7 +733,7 @@ static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info, > > if (err) { > > con2fb_map[unit] = oldidx; > > - module_put(info->fbops->owner); > > + fbcon_release(info); > > } > > 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 = oldinfo->fbcon_par; > > - int err = 0, ret; > > + int ret; > > - if (oldinfo->fbops->fb_release && > > - oldinfo->fbops->fb_release(oldinfo, 0)) { > > - con2fb_map[unit] = oldidx; > > We don't need oldidx any longer? > > There's some logic wrt to the parameter 'found' here and in set_con2fb_map() > that appears to be relevant. Yeah further patches clean this up more. Or did you see a potential bug here? I did ditch the fb_release error handling, simply because there's not really much we can do anyway, it shouldn't ever fail (that's a driver bug) and it was convoluting the code for no gain. But I might have missed something in this cargo-cult. -Daniel > > Best regards > Thomas > > > > - if (!found && newinfo->fbops->fb_release) > > - newinfo->fbops->fb_release(newinfo, 0); > > - if (!found) > > - module_put(newinfo->fbops->owner); > > - err = -ENODEV; > > - } > > + fbcon_release(oldinfo); > > - 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 = 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 = 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 = 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 = newinfo->fbops->fb_set_par(newinfo); > > - 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); > > } > > - return err; > > + return 0; > > } > > 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 = &fb_display[fg_console]; > > struct vc_data *vc = vc_cons[fg_console].d; > > const struct font_desc *font = NULL; > > - struct module *owner; > > struct fb_info *info = NULL; > > struct fbcon_ops *ops; > > int rows, cols; > > @@ -938,17 +944,12 @@ static const char *fbcon_startup(void) > > if (!info) > > return NULL; > > > > - owner = 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; > > - } > > ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); > > if (!ops) { > > - module_put(owner); > > + fbcon_release(info); > > return NULL; > > } > > @@ -3314,10 +3315,6 @@ static void fbcon_exit(void) > > } > > 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 = info->fbcon_par; > > @@ -3327,6 +3324,8 @@ static void fbcon_exit(void) > > kfree(info->fbcon_par); > > info->fbcon_par = NULL; > > } > > + > > + fbcon_release(info); > > } > > } > > } > > -- > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 N?rnberg, Germany > (HRB 36809, AG N?rnberg) > Gesch?ftsf?hrer: Ivo Totev -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch