Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2665963rwl; Sat, 1 Apr 2023 11:59:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Yz2GW/sTPNShl6J1+gwDYt6RjqHAN0n0XNGQB+WD/Kz1pLznAfj3r2a/WlZhJZww6CLUZo X-Received: by 2002:a17:907:1df0:b0:8aa:33c4:87d5 with SMTP id og48-20020a1709071df000b008aa33c487d5mr10729315ejc.10.1680375592401; Sat, 01 Apr 2023 11:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680375592; cv=none; d=google.com; s=arc-20160816; b=YkTcOS8hOcJ+ba5ljpEXcvDshzzhniCFydFuGRFUSR8G7JbI6sedEc9C/tjud3SD9/ KG0gqP5Wwu4mg+BC8IJW46A6yIpMeOb7MLicUGGq3vqzpYmp6Oz5vwEnU+muG72VuFE1 ugVYItKPC4jfXHsysHb/uEvTQm/466fzhHIQRufP2h7lUEcUEuGQQ7lbb3aIHpURu3Rn 4qG753aLHVxinZk8mbZp/DdKbNf6Z5WloLunqJmLcE4LwoCgHDcOT5LzPpKkdsnt+nw2 RgYjiPDyTiqBSchPxybFZ7Wf6XkAjnp38dRby6U6G2xhd9pXg7qoIvvSFVbQ4Adfy2aV Jajw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ILffRSxfHBaQccw0B4WkD1ay95uCakC9dhk9TVI48DU=; b=HfC0BwT9w3qokLhVkgSdo3XMvbpIT3/BuGCQfJ6ght9j3NS//RqMMjBW+zOiH3I4Ox h0OqCveimbXTkQSt9EysqbCRzBke5yVmR5J5x+Za+hkT1e8XzB2GQIG47epNQQ0gZra5 PZBs6ObSBfW2EbR4rlN9aMQv911Az5VkxqH+JffNZp0NJ1eCRuzLKXBstIWT+X3/70nB Q21mKlWyc5aaWhItOLb060ohmF/WG9qA+7K3Hwk1b1BecWwsGqZtBZqHQYnjUJ5xbHp1 Ep5mfAgkEEeOCgvdqhOQuW173aBVr4n7YDsQRb7YeLJ2hq58nc43PO/ilGVG7THPpAhz 3FvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s20-20020a1709064d9400b0093ec7db2010si4273795eju.665.2023.04.01.11.59.27; Sat, 01 Apr 2023 11:59:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbjDAS5e (ORCPT + 99 others); Sat, 1 Apr 2023 14:57:34 -0400 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 S229672AbjDAS5c (ORCPT ); Sat, 1 Apr 2023 14:57:32 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A439B766 for ; Sat, 1 Apr 2023 11:57:31 -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 331ItuHl030779-331ItuHm030779 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 2 Apr 2023 02:56:01 +0800 From: Gencen Gan To: Gerd Hoffmann , David Airlie , Daniel Vetter Cc: Gan Gecen , virtualization@lists.linux-foundation.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm/bochs: fix ioremap leak of mmio in bochs Date: Sun, 2 Apr 2023 02:55:43 +0800 Message-Id: <20230401185544.3027703-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 X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 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->mmio won't be freed. We just need to release mmio in the corresponding error handling. Signed-off-by: Gan Gecen --- v1->v2: Change the strategy for fixing this issue to manually release mmio by iounmap instead of changing ioremap to devm_ioremap. drivers/gpu/drm/tiny/bochs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c index 024346054c70..46abed11c163 100644 --- a/drivers/gpu/drm/tiny/bochs.c +++ b/drivers/gpu/drm/tiny/bochs.c @@ -243,15 +243,20 @@ static int bochs_hw_init(struct drm_device *dev) * 64 * 1024; if ((id & 0xfff0) != VBE_DISPI_ID0) { DRM_ERROR("ID mismatch\n"); + iounmap(bochs->mmio); return -ENODEV; } - if ((pdev->resource[0].flags & IORESOURCE_MEM) == 0) + if ((pdev->resource[0].flags & IORESOURCE_MEM) == 0) { + iounmap(bochs->mmio); return -ENODEV; + } addr = pci_resource_start(pdev, 0); size = pci_resource_len(pdev, 0); - if (addr == 0) + if (addr == 0) { + iounmap(bochs->mmio); return -ENODEV; + } if (size != mem) { DRM_ERROR("Size mismatch: pci=%ld, bochs=%ld\n", size, mem); -- 2.34.1