Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2624198pxj; Mon, 31 May 2021 06:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0MeCcSGBbS/2U57pkBZOxyszTFuUaJgl+Zj24VNewE27J81b1WptDaBSmsDntUjby7Nkr X-Received: by 2002:aa7:d786:: with SMTP id s6mr25109921edq.239.1622469002229; Mon, 31 May 2021 06:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622469002; cv=none; d=google.com; s=arc-20160816; b=keiDApP92zfd5MDoCpYKAHGOxwkHqNvTEDnex8aoOMCWT0PpHkxAV5taaq1RNnaGfY tXnywhNXYjvf25EFR4dWXrJ1zNoNQN/St2cH652iYx0Kez/0X0Hcm9stuiimogBcqyOy m6eipesAG1IXFXegqesmPIRibqxJT9UXeXHgLVsz4GuNp/bp7U50Gah77A7vOKQG5c+b sLlYjIr46CkdyGkGbC37RoeFxiwM8eGp/DJ5VgiqMX8JFOM5PlUoqtw4Rry9vOTriN5P p5+tvo6EVN0695wA88U07c4R5HibMEPyoep+h7iUJ+ynmEVqhfUaot+yA515aH7X7eTj YwHA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gECUWe+Ksx/zwk3a6uTO2rNZjl/HcP+aSe2UEp85rcA=; b=f4LvP6O6P5/w4jQCYFtGGeknuEgaEaZ1A6bwDgOJse+wS9Wzq3dxr0bjgfXWg3Kfx0 UFkaKbPbOGlUlWgboe7R+w3+FxZXY67DziD80fn6xGMmLP4R1IcoDvXK26Ze4Hpew4TG N41idRQGIv7pYiPuXX3JdTw8dspxHLyTfQoBWpTMSgplODoqnxcl4B1SbG8WT/75dtrN BpRXcteVihro2CxbEEYICIi/hJkvRrTCVuwlV6lPQDtCawD+KOMgplNiW93mSmNq3ehF 5lUOYkk8kLswhtQTnaUMRzeLhvOzCS/sLF4kOozrSghFDqNcmtNS/okEUX+Yg1ia3stt jRow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zvZ2DSnK; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si8369977edz.576.2021.05.31.06.49.39; Mon, 31 May 2021 06:50:02 -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=@linuxfoundation.org header.s=korg header.b=zvZ2DSnK; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232782AbhEaNsd (ORCPT + 99 others); Mon, 31 May 2021 09:48:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:39238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232642AbhEaNd1 (ORCPT ); Mon, 31 May 2021 09:33:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5B8A76143C; Mon, 31 May 2021 13:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467477; bh=qimJcXLAlvslZZS3a36NHFGUNOy7xM10vdpvTwjf1k8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zvZ2DSnKwg+tvkDsAHoGq4mx0gOxJk3iT2Sp0CTgGGoJ5WLLI34dHstpl/fhghd16 bkK7c3UDCM4Wh4S+WG+pNEHCfJqeX2ZjPO+7EbLoga3rRrxgT1LgrkwssC71kQtcgr FL9ud5Oh2UEcB1sivchHJYUT7NrZkEKbFp29IHsA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "David S. Miller" , Phillip Potter , Sasha Levin Subject: [PATCH 4.19 081/116] isdn: mISDNinfineon: check/cleanup ioremap failure correctly in setup_io Date: Mon, 31 May 2021 15:14:17 +0200 Message-Id: <20210531130642.909457873@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Phillip Potter [ Upstream commit c446f0d4702d316e1c6bf621f70e79678d28830a ] Move hw->cfg.mode and hw->addr.mode assignments from hw->ci->cfg_mode and hw->ci->addr_mode respectively, to be before the subsequent checks for memory IO mode (and possible ioremap calls in this case). Also introduce ioremap error checks at both locations. This allows resources to be properly freed on ioremap failure, as when the caller of setup_io then subsequently calls release_io via its error path, release_io can now correctly determine the mode as it has been set before the ioremap call. Finally, refactor release_io function so that it will call release_mem_region in the memory IO case, regardless of whether or not hw->cfg.p/hw->addr.p are NULL. This means resources are then properly released on failure. This properly implements the original reverted commit (d721fe99f6ad) from the University of Minnesota, whilst also implementing the ioremap check for the hw->ci->cfg_mode if block as well. Cc: David S. Miller Signed-off-by: Phillip Potter Link: https://lore.kernel.org/r/20210503115736.2104747-42-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/isdn/hardware/mISDN/mISDNinfineon.c | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/isdn/hardware/mISDN/mISDNinfineon.c b/drivers/isdn/hardware/mISDN/mISDNinfineon.c index 3e01012be4ab..95a0d728eecc 100644 --- a/drivers/isdn/hardware/mISDN/mISDNinfineon.c +++ b/drivers/isdn/hardware/mISDN/mISDNinfineon.c @@ -645,17 +645,19 @@ static void release_io(struct inf_hw *hw) { if (hw->cfg.mode) { - if (hw->cfg.p) { + if (hw->cfg.mode == AM_MEMIO) { release_mem_region(hw->cfg.start, hw->cfg.size); - iounmap(hw->cfg.p); + if (hw->cfg.p) + iounmap(hw->cfg.p); } else release_region(hw->cfg.start, hw->cfg.size); hw->cfg.mode = AM_NONE; } if (hw->addr.mode) { - if (hw->addr.p) { + if (hw->addr.mode == AM_MEMIO) { release_mem_region(hw->addr.start, hw->addr.size); - iounmap(hw->addr.p); + if (hw->addr.p) + iounmap(hw->addr.p); } else release_region(hw->addr.start, hw->addr.size); hw->addr.mode = AM_NONE; @@ -685,9 +687,12 @@ setup_io(struct inf_hw *hw) (ulong)hw->cfg.start, (ulong)hw->cfg.size); return err; } - if (hw->ci->cfg_mode == AM_MEMIO) - hw->cfg.p = ioremap(hw->cfg.start, hw->cfg.size); hw->cfg.mode = hw->ci->cfg_mode; + if (hw->ci->cfg_mode == AM_MEMIO) { + hw->cfg.p = ioremap(hw->cfg.start, hw->cfg.size); + if (!hw->cfg.p) + return -ENOMEM; + } if (debug & DEBUG_HW) pr_notice("%s: IO cfg %lx (%lu bytes) mode%d\n", hw->name, (ulong)hw->cfg.start, @@ -712,9 +717,12 @@ setup_io(struct inf_hw *hw) (ulong)hw->addr.start, (ulong)hw->addr.size); return err; } - if (hw->ci->addr_mode == AM_MEMIO) - hw->addr.p = ioremap(hw->addr.start, hw->addr.size); hw->addr.mode = hw->ci->addr_mode; + if (hw->ci->addr_mode == AM_MEMIO) { + hw->addr.p = ioremap(hw->addr.start, hw->addr.size); + if (!hw->addr.p) + return -ENOMEM; + } if (debug & DEBUG_HW) pr_notice("%s: IO addr %lx (%lu bytes) mode%d\n", hw->name, (ulong)hw->addr.start, -- 2.30.2