Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2667121pxj; Mon, 31 May 2021 07:48:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJxccE572VI59dLRGpP9ZYvxcLGd7uxjpcnqToXqIPng6pDZFbniznXXMQRlopj+dCo9pa X-Received: by 2002:a05:6402:695:: with SMTP id f21mr11027279edy.96.1622472538467; Mon, 31 May 2021 07:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622472538; cv=none; d=google.com; s=arc-20160816; b=xAIOEzl94bUQeDuHgj3gPeVRh4O1oOZgjBRxdKJi6UKEHkehN/rEPBeinNJMAt9Rrl nKGY9tmhB1v79ADtp6sFlTBcaPE+H8CovlPSnnN/4ZT3MdrnD5MeLEy/WFaOezH8Fx32 QNOnrMAUGq5ITpqJs28iPQ/xsBmeuKyoqZ3RGq13HrCc1DdAojqNA0HamvWlZkaYsO+s fCADhgTP5ZTz1alYxX/uF/zbCUV23TGmqBowL/NtYGNy3gqShS7MrgG+vij4EJJaHpEM krwlZA+5vFAcoEtItMSwUEVjTLl0kz0ChlLnesXViReuc/q+q+dGA5LSQNMMrVvdUJip 2LWQ== 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=L1ytDV4lZ/J7t0S3DVAqLTCPA9ig4C89CqLhnZZVpm0=; b=f6z43YaE/qrJKFEtpvBBxx+wgZFS1ujqOlnMKR6/XwEati0qCeSJjdOMMQ63Xvx/1g W1r4L4D43PbXCOtdtDLKZ0jziZ8izafZtoUcj/ees9YRJ4UcD3koR3NmS3AMV9UXISJx O8vir7Z2/HkT1arRvWY7vLfC1iZfPv6OkQtZXv5g7z9eELKASZ5fw2sMsIkcmmRi8u3Y wShhF8fp4slHUu7Fnu6mH8FGk7V8wmjmRt+Ix+Mt/bgZxjKxoZBt2jdvJuyZTeBikxhH QpK2eKGLYNBYaPs9LMz8oHLzcHjnLf3uwove+1bVRlk3qUPz1j3a7BUPMy7PdwZo8ctO 9o6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fyw7LDFn; 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 e7si4819649edk.213.2021.05.31.07.48.36; Mon, 31 May 2021 07:48:58 -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=fyw7LDFn; 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 S233787AbhEaOrX (ORCPT + 99 others); Mon, 31 May 2021 10:47:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:60840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232174AbhEaOAc (ORCPT ); Mon, 31 May 2021 10:00:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0F53561941; Mon, 31 May 2021 13:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468191; bh=euRLIJDH25ZoSnSBxdxzZ317rlc/qZqkNqj/3eTS1xc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fyw7LDFnF2vTjuQTn7PtmVPPiRucYGmCtA95pSHzgNlOMVd5v5w6QZartW0I4AjPG 9ByYqJD9s4wAndF/R5WPkbrf/y7JSsjHvWbyrut5ObN267/xjDVWp7d2tUbGJtgVFP ZXFi0cHE5q5wDdRrpTAsPFSR9LpjTdv6lDE7z9TQ= 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.10 149/252] isdn: mISDNinfineon: check/cleanup ioremap failure correctly in setup_io Date: Mon, 31 May 2021 15:13:34 +0200 Message-Id: <20210531130703.075006963@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@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 fa9c491f9c38..88d592bafdb0 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