Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2247302ybz; Thu, 23 Apr 2020 14:25:38 -0700 (PDT) X-Google-Smtp-Source: APiQypLOkBeJFzd8g5/h7fo19cEkEbfC4QoBrK7z2OffYYpcNbAqrcUMqW8xL5ldXPeKxCsU3ZZI X-Received: by 2002:a05:6402:88a:: with SMTP id e10mr4481391edy.252.1587677138337; Thu, 23 Apr 2020 14:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587677138; cv=none; d=google.com; s=arc-20160816; b=bH7lsp2tk2KDIo7/JyupoBmriCbvFSLVpFSuuAU8dyDMBM3ypowJR+bTVug9lkR+RS vFbH5m4PFExj0YQGawyyupEQ/dAoiS3N/0LVWxZkhjq47G4DsgRKN1St8S4hg01YoW1b SQudXlkqgcctV/68BiR/yIEIZsYjX2JEfwTrhOqM90NImRbgnX8KjRR6O+DvWiWXWEh3 neXxhKU3siBXRQh2DB4IQMB9nmQkZnTBnF1GyuFpg04xo0EjbMHQwZCE3DpKHntas0KL DHmASRnpBCj8/kuEM7FC8RoFbmu+yaytym5E+AuAM26HL99jcblxJZ1flONskOheggxD aulQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=XUMoGhY5L7Ce12qPN/+ZvR9RdaPKROuCE+nbwYYQZjo=; b=BKwJseHRthp1VljJs6m/hmrM3g261obRYE9ovXRI86wXsEXpRmxsgeiy9WBg09mRav 3xBQ48PSGwV1+11hOFXVd/z2H8C5x4c7b+8k9ko2eDoOn/MIoGBj3lqMYBx3rfTeG4Rc sGY3IPQuD0FM39I9Hn2tM6VnYvVCyATLMUKeSBdanjPxojz8iPCTVwPDSvubVLnsPIx9 7e/ZFKzduJ7DdWALpUUeuCuDaMsG2vhZ86DB1VzZfrRcjWeRH2RrYxxehbibiKcEhhIx CWT0p5jx7LcOt/c6cfOErcRNaSDevMzIdllRS2Fc99rydgpNTddt1/jPIL2drDbfR+W/ 2LJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="s0/OP9DD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gl22si1498535ejb.402.2020.04.23.14.25.13; Thu, 23 Apr 2020 14:25:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="s0/OP9DD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726487AbgDWVXp (ORCPT + 99 others); Thu, 23 Apr 2020 17:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbgDWVXo (ORCPT ); Thu, 23 Apr 2020 17:23:44 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45727C09B042; Thu, 23 Apr 2020 14:23:44 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id r14so3631514pfg.2; Thu, 23 Apr 2020 14:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XUMoGhY5L7Ce12qPN/+ZvR9RdaPKROuCE+nbwYYQZjo=; b=s0/OP9DDA3gkPf7NIb24mAh7l/E0qodqA1SOp9ziVmNnIO9fT1oyN0LqMv9o8L6cen aeolu96fv+P5eTrlCkNWKxCnSM5ynJO+jOCCnD876QvT1ehFUguZKa+fBN6STq19O97O CiSJHOHTJcGiurWOmlLB1qHssbx4D74cfm9x0/fQS+rfmkru01P064qg/bnR3v4epEQh TCORYK94sO0/9w08wp1/9p2v3kB56BoaHNZ3XLFvV8JaQAZuRa/mzaLQxwyDc972iOBO WbiNhpWsdPTip3BN3vU8Tdlk8uVXTq3w4rfWnC8/sBaX1OCT5xwnSys8Ir+UFqeGjNhP UBdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XUMoGhY5L7Ce12qPN/+ZvR9RdaPKROuCE+nbwYYQZjo=; b=TQwToyJeYmiT2ZtTVZidyFTZsAlLFe/NWujXuoZvyUQ7Qe7ia97FXH8FXgknk+HLpq EjY7UUBfNVZDqdDqCR8r7KzOfxuscBQEsOYPrBYcOC9eJ4cLgNaUYeuhEEs4R7mywiZN 3LNjO1R/OWekN+EI19ySu60eIFQynWooMip/53zRH4rjGD5yVXrCllCY4kVNA+g1NznW GEWCWGKP8qsd3OsFGChB9NM9lg+sfrjTFJ/k0xgzpY6hS/rQ3rdpGVQR7C7rtgSPEUHN l1zHkEPhQliIV/W5Hc6DU5M/AgtuRgG/qVUwb3baeN1rNrWn2KAbKKB7+6ltk6sFW48K B9vg== X-Gm-Message-State: AGi0PuZQKh3xgRI5fghPG68I3P+E8sRwyHRe9JBHkzXqYYq/+aQq6OsI jVuwTgLbk33+64iqTj92ZO9JYoUruXIghP++dSI= X-Received: by 2002:a63:1c1:: with SMTP id 184mr6033217pgb.203.1587677023745; Thu, 23 Apr 2020 14:23:43 -0700 (PDT) MIME-Version: 1.0 References: <20200423164251.3349-1-zhengdejin5@gmail.com> In-Reply-To: <20200423164251.3349-1-zhengdejin5@gmail.com> From: Andy Shevchenko Date: Fri, 24 Apr 2020 00:23:31 +0300 Message-ID: Subject: Re: [PATCH v3] console: newport_con: fix an issue about leak related system resources To: Dejin Zheng Cc: Bartlomiej Zolnierkiewicz , Greg Kroah-Hartman , Thomas Gleixner , akpm@osdl.org, dri-devel , linux-fbdev@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 23, 2020 at 7:42 PM Dejin Zheng wrote: > > A call of the function do_take_over_console() can fail here. > The corresponding system resources were not released then. > Thus add a call of iounmap() and release_mem_region() > together with the check of a failure predicate. and also > add release_mem_region() on device removal. FWIW, Reviewed-by: Andy Shevchenko > Fixes: e86bb8acc0fdc ("[PATCH] VT binding: Make newport_con support binding") > Cc: Andy Shevchenko > Suggested-by: Bartlomiej Zolnierkiewicz > Signed-off-by: Dejin Zheng > --- > v2 -> v3: > - modify commit tag CC to Cc by Andy's suggestion. > - modify Subject 'console: console:' to 'console: newport_con:' > by Bartlomiej's suggestion. > - add missing release_mem_region() on error and on device removal > by Bartlomiej's suggestion. > - add correct fixes commit, before this patch, add a wrong 'Fixes: > e84de0c6190503 ("MIPS: GIO bus support for SGI IP22/28")' > thanks Bartlomiej again! > > v1 -> v2: > - modify the commit comments. The commit comments have some more > appropriate instructions by Markus'suggestion. here is my first > version commit comments: > > if do_take_over_console() return an error in the newport_probe(), > due to the io virtual address is not released, it will cause a > leak. > > drivers/video/console/newport_con.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/video/console/newport_con.c b/drivers/video/console/newport_con.c > index 00dddf6e08b0..2d2ee17052e8 100644 > --- a/drivers/video/console/newport_con.c > +++ b/drivers/video/console/newport_con.c > @@ -32,6 +32,8 @@ > #include > #include > > +#define NEWPORT_LEN 0x10000 > + > #define FONT_DATA ((unsigned char *)font_vga_8x16.data) > > /* borrowed from fbcon.c */ > @@ -43,6 +45,7 @@ > static unsigned char *font_data[MAX_NR_CONSOLES]; > > static struct newport_regs *npregs; > +static unsigned long newport_addr; > > static int logo_active; > static int topscan; > @@ -702,7 +705,6 @@ const struct consw newport_con = { > static int newport_probe(struct gio_device *dev, > const struct gio_device_id *id) > { > - unsigned long newport_addr; > int err; > > if (!dev->resource.start) > @@ -712,7 +714,7 @@ static int newport_probe(struct gio_device *dev, > return -EBUSY; /* we only support one Newport as console */ > > newport_addr = dev->resource.start + 0xF0000; > - if (!request_mem_region(newport_addr, 0x10000, "Newport")) > + if (!request_mem_region(newport_addr, NEWPORT_LEN, "Newport")) > return -ENODEV; > > npregs = (struct newport_regs *)/* ioremap cannot fail */ > @@ -720,6 +722,11 @@ static int newport_probe(struct gio_device *dev, > console_lock(); > err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); > console_unlock(); > + > + if (err) { > + iounmap((void *)npregs); > + release_mem_region(newport_addr, NEWPORT_LEN); > + } > return err; > } > > @@ -727,6 +734,7 @@ static void newport_remove(struct gio_device *dev) > { > give_up_console(&newport_con); > iounmap((void *)npregs); > + release_mem_region(newport_addr, NEWPORT_LEN); > } > > static struct gio_device_id newport_ids[] = { > -- > 2.25.0 > -- With Best Regards, Andy Shevchenko