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 27C5AC74A5B for ; Tue, 21 Mar 2023 09:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbjCUJye (ORCPT ); Tue, 21 Mar 2023 05:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjCUJyc (ORCPT ); Tue, 21 Mar 2023 05:54:32 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1A8C23126 for ; Tue, 21 Mar 2023 02:54:29 -0700 (PDT) Received: from liber-MS-7D42.. ([10.12.190.56]) (user=gangecen@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 32L9rEfp018165-32L9rEfq018165 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 21 Mar 2023 17:53:19 +0800 From: Gencen Gan To: Gerd Hoffmann , David Airlie , Daniel Vetter Cc: Gan Gecen , Dongliang Mu , virtualization@lists.linux-foundation.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/bochs: replace ioremap with devm_ioremap to avoid immo leak Date: Tue, 21 Mar 2023 17:52:16 +0800 Message-Id: <20230321095216.1306555-1-gangecen@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: gangecen@hust.edu.cn Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gan Gecen Smatch reports: drivers/gpu/drm/tiny/bochs.c:290 bochs_hw_init() warn: 'bochs->mmio' from ioremap() not released on lines: 246,250,254. In the function bochs_load() that calls bochs_hw_init() only, if bochs_hw_init(dev) returns -ENODEV(-19), it will jumps to err_free_dev instead of err_hw_fini, so bochs->immo won't be freed. We would prefer to replace ioremap with devm_ioremap to avoid adding lengthy error handling. The function `devm_ioremap` will automatically release the allocated resources after use. Signed-off-by: Gan Gecen Reviewed-by: Dongliang Mu --- drivers/gpu/drm/tiny/bochs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c index 024346054c70..0d7e119a732f 100644 --- a/drivers/gpu/drm/tiny/bochs.c +++ b/drivers/gpu/drm/tiny/bochs.c @@ -223,7 +223,7 @@ static int bochs_hw_init(struct drm_device *dev) } ioaddr = pci_resource_start(pdev, 2); iosize = pci_resource_len(pdev, 2); - bochs->mmio = ioremap(ioaddr, iosize); + bochs->mmio = devm_ioremap(&pdev->dev, ioaddr, iosize); if (bochs->mmio == NULL) { DRM_ERROR("Cannot map mmio region\n"); return -ENOMEM; -- 2.34.1