Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2705466pxj; Mon, 31 May 2021 08:41:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQHM16AZdcfWPC7Zw+4eGWTpvoCX334lywHyXhV5QDv0+puJpi7SdnRp8eBhZNjnOFLSSx X-Received: by 2002:a17:906:744:: with SMTP id z4mr23895310ejb.347.1622475691517; Mon, 31 May 2021 08:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475691; cv=none; d=google.com; s=arc-20160816; b=B2npwpYV/ZGHuzT2w7q+BOzWUOJ7+gLzvVtg2ppBkJuKy2ccqdX9dFB5Q8DFH6U1Pg 6fjura5utydRf2s/UcBsjunjFFa3fxVmwVflUOu/VAtImSgKwPGgFg1w1ADrcgHjhDbx dZj6QztPuNvEZgBG7fdzaxhtmXqGkD1f0/jCJSQEaTcVyeOxrPCpGsrTQIvgIZ/RwJSE o4k/enLPWQU8qg+2Rvpq0uRfYA1RwOMHsS2Nr4QGZlS9tzBxxmtn81E+6G9U11FJkN6o 0gvDlGld+BwxlWh9I2c9qc4qkrcveFCNZogGkwX9oKTl2gyYp7/9zfAu4FQkl5pcEbOq AAgw== 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=wupDQDX31MN8DxUaLPYNLlpZWdPJHBjej5K2ZukEOks=; b=nvfUkBp4wW9t0S1TGUDmsQhubGFZ7qhFniOh8qN3yb845JvDOBmQSxLmWK7sOsUJ8Q tGANRhMuIcodEhmtS9zpRjCSxsBhFeuo6Gk8OL9b7uf/RBTnTG4j+sf+8DNsgQphZ6+G 3o1QP3U+oEuNnwj/4uH7llP0188Ja0ygcMTYx2XNVbwtq6hw/SoYuCpQoGcHJblTOJir FSTNTFrkKgIGp3Stcdiw8LdlBJe1X8x1DHERcLqGM+3p1dq5roi6/I03r6sw92u/EEl5 TlXE3qo8O5WV1JruOLfhpoiPceLtwarpJmPmciF4hagVJAo92MWzRdCaHMGJpX59OBVD loPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JnKAP88E; 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 y14si11375947edc.428.2021.05.31.08.41.07; Mon, 31 May 2021 08:41:31 -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=JnKAP88E; 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 S234825AbhEaPkJ (ORCPT + 99 others); Mon, 31 May 2021 11:40:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:47642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234025AbhEaOWR (ORCPT ); Mon, 31 May 2021 10:22:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BDC80619F1; Mon, 31 May 2021 13:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468721; bh=yKmHGYlo9dLU4grjc3FlxN0rPL/SRMFjd9gHx/aD5cU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JnKAP88EoU7fTtOQY/TaG5HchOBlV+bMARqqLj7Z1F+EyTQ5bJgFZ8CEViM46kAO+ V/6YY4qiC7CAeefOa/L9r0/E9ZnoXra7Hzv0t+iXjub9ypQ/KyNAoLkVkVnD2N4kn2 YrDn1gErtctEb4vKQATTRpV2hcGNlf7EHvioEwMI= 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 5.4 102/177] isdn: mISDNinfineon: check/cleanup ioremap failure correctly in setup_io Date: Mon, 31 May 2021 15:14:19 +0200 Message-Id: <20210531130651.424185830@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 d62006bab9c6..3cf0c6f5a1dc 100644 --- a/drivers/isdn/hardware/mISDN/mISDNinfineon.c +++ b/drivers/isdn/hardware/mISDN/mISDNinfineon.c @@ -630,17 +630,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; @@ -670,9 +672,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, @@ -697,9 +702,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