Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1998842ybz; Thu, 23 Apr 2020 09:46:57 -0700 (PDT) X-Google-Smtp-Source: APiQypJCLUByw/zaYc/hVlZ2waTAiGtnnk3iTcTKlvP4xbNPOql8FEebBlYYriyyj2KDoAX0Aj7H X-Received: by 2002:a17:906:f295:: with SMTP id gu21mr3557668ejb.83.1587660417554; Thu, 23 Apr 2020 09:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587660417; cv=none; d=google.com; s=arc-20160816; b=zca6UnJIfNoe51rYFD7y1pHuiSjpnmKzntc5lo1CEPM6eTld+MfRs2gJyILiCT0Me8 80BITFJicAqwxy3dycB8u8odUZr4A5v7WzuwFZ4bIqNGq5e1WI9s7neARZ2piuwBGOld RNNrtB+ZmFY94/WVqLp5Hw13YjkKGQlByUJZdJMdk/cUXRTp+KCkUJH3g+zMJKbH/3ck nMnlwVNQcEGz6M2rj3IEH+jX0Etmd9PV3M/9qSlP8E98ZSAq+MHr1WF4zThwq2NLTq+1 YfmDh+/J8GkG4XZhLLPWYDCQLABCYbY4f4rDaqlYtQKx+BunQOGlcPH47qQPmkyw/qR+ C08A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=g0Ejxu1wuqWuETn/IJMRXxxZQ/rRlbjvuR8vLOOTtDU=; b=Nl19a818vwoSXpfNs7QsKsFrv3I1/k58FPiksnfYlWaWtCAxO1/XW3kXzFHaR0VWj+ ruXkUWJ7zLQR/w/lk04H7DZTPMbzFSn0unyq65WP1+4GWLptqvMMHZA/pvtr6KKBwHrL y/vbKUZdurbeEemrsuW7TrdJIOKJ0nwZ67eXsQi+crzS1jLjTzYCGIZE3G9G/iqQDsEO crIWc3GU9MxojqQYMIUjV8kRAHHoQYpDstTmfYAe/28ANzOZ11jcgydWogC1UTmOcj0s 124iV+QlToDhDz850RV7/4IF78MQo9wKyPzFV3StD+ZyFMUOKKZNCausmzISRy5fMuyk RcxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IJAabNre; 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 h21si1553179edj.79.2020.04.23.09.46.33; Thu, 23 Apr 2020 09:46:57 -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=IJAabNre; 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 S1729758AbgDWQm7 (ORCPT + 99 others); Thu, 23 Apr 2020 12:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729407AbgDWQm6 (ORCPT ); Thu, 23 Apr 2020 12:42:58 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67112C09B041; Thu, 23 Apr 2020 09:42:57 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id 18so3219347pfx.6; Thu, 23 Apr 2020 09:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g0Ejxu1wuqWuETn/IJMRXxxZQ/rRlbjvuR8vLOOTtDU=; b=IJAabNre2tTWjnak57Stl3OhpAV/rvj4wnWO1M3yc6RjzjaIAv2BTTo9M3W4aTmQK2 1nkfWVe8viMZQMVqM7Ggb5rElkaK6nVmUpmsfxpeUgK85pfnIA+DfPWB+q/rqK80Chqq WcJwZttjVCByfGO7lkWczHDFKgIW1Bwk1huREmPw5O4MxEV0jgx/LXdiG18OFARjhrDT YsPHtvJKMfnHdGqF+CRSEBr+J2T3NTDSlyBxabUTTJE/+LC++HQrs1RLA8mYBOgcg4Q/ 3vZGSZ7EqishFfz+8E2CZtBRw2Xl7PtKJ7ZjEFKvpE4cZNEkdttNfVYAv19ydSCyCiDi iqLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g0Ejxu1wuqWuETn/IJMRXxxZQ/rRlbjvuR8vLOOTtDU=; b=Kb1rnfx5ybhu9UyHonoueKfpmSRgum/bqbKavU2zC7fhVr7teXEhF2l2CXH7Y5vYRq a2Vw/nvswPT/r8XYfPMPaq5M6a9YANjEqQ2yJeEC0XhqXw1dCY9nofkUypYWXwehVQHo oYHXvi0YaqYpOGtPfHkVEXkjPAJisTZmoICLLSu6RSoMbatq0tl2blljXvng0shARtOa EKbs5prAuX1gQD5FBHUZqzWERzb+7Dp1MZh59h8DD/ce233ovvbZb1KBva0aCzVlPshT TdvN48hb2u5cLFUJ3l3seS5ihZoas8gKG8ie0ScVhrrkBwm6XSHvuqjmXqQneRT0bxFv qLnQ== X-Gm-Message-State: AGi0PuZB4Lq/F2z/lEtBV6sn5rZgD6ogrBjnxXEOGb16S3rNx3jIG8If oZdYCIrCYdJwzIKdtk+GHtA= X-Received: by 2002:a63:e607:: with SMTP id g7mr4676487pgh.303.1587660176929; Thu, 23 Apr 2020 09:42:56 -0700 (PDT) Received: from localhost (176.122.158.71.16clouds.com. [176.122.158.71]) by smtp.gmail.com with ESMTPSA id p24sm3061668pff.92.2020.04.23.09.42.55 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Apr 2020 09:42:56 -0700 (PDT) From: Dejin Zheng To: b.zolnierkie@samsung.com, gregkh@linuxfoundation.org, tglx@linutronix.de, akpm@osdl.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Dejin Zheng , Andy Shevchenko Subject: [PATCH v3] console: newport_con: fix an issue about leak related system resources Date: Fri, 24 Apr 2020 00:42:51 +0800 Message-Id: <20200423164251.3349-1-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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