Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1023026ybe; Wed, 4 Sep 2019 11:17:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUi/7J/AUVKl3Xu0gmEn2NEsmvAw7gIknY+pKHOtSGBGFOR07rfH39kSycbq78t5tZ56nN X-Received: by 2002:a17:902:36a:: with SMTP id 97mr15549003pld.61.1567621042139; Wed, 04 Sep 2019 11:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621042; cv=none; d=google.com; s=arc-20160816; b=WU1ZQ+ncVcTpb/d9HSmocTtXBCwMkyKXxwyvwHY9XYm8SgQW8YceGJwn/tqspizynw cjUQqoRFR/SSI+9K9csmtJEPA+38dKUyRDchr/u+FI3EZRBvWacNYsmva3OVuErWx4FN 4Msy4T8CAOUGRMovbNgCBiQBHXBc2Birzb39Tb99i9+D7IELNfp5Htx4FA7UOuqtz4L8 ecSXabRSYNBv90ON+iV8Q9PLuu3u8UJuu2/QSLItlLf1a7e5n98qq7eWkPl4gv+TfVuY biDIHVcG6ftXU6uzpQ1evCj0l/PsF2WiNrIrEOL90KwDi5fQ6IlMAohOAV+9VG3m0ek4 avbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s5hrPziqRfZjLWZJOvxvO5X66NcgwH29zvM09VrJcTs=; b=CqNa40uLsrLsUj5QgcRYWprZvvnzXCV/bC5HHjMu8Zsk1cMeQhNwtoqEGjeCx9YZMZ AZxfsdSK0IU6pWmdUR4ZGfjB/b2yrIejvL0PwYvO6s3/wwQ/hIjfuARsw/5treqcRl9H N+FoRaTKKK0cBai8nrpkqSmykm83Hw2Fp9nWbXezOFPlKJ727ET8+7hs5x6HOHcGtPUA oZhiPVby/EKP/oKq1CNSi41zOJcWyWARWk5xw4m7QIDPRmihLEsxvvlRxA4gsCQQmhiG 9oe/BcmluWxE/Rjauo5ajv8GRfDDP0Ywf+TJPn6OutM3dlTVCvyHd1p31jNPjT6I4Z9K gHeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LJATrdsI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m184si21890077pfb.127.2019.09.04.11.17.06; Wed, 04 Sep 2019 11:17:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LJATrdsI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390358AbfIDSPs (ORCPT + 99 others); Wed, 4 Sep 2019 14:15:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:32824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390393AbfIDSP3 (ORCPT ); Wed, 4 Sep 2019 14:15:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9E44F2087E; Wed, 4 Sep 2019 18:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620929; bh=UbwxphCkJgqkkmqkEGI327ZtsTfNouQD7+qWRvtcpI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LJATrdsI1qtyD4e0xUfQIx7wwktQ+SgtFjUUKeEQv+hGmdLcIyL7zmhzjIgHQ0oPv XfLqRclFriEhK0NbzqydTIW92eADE5dhR1vlZa6fHXKNqYhkT6Er/3BgD3nwuNsk3f QzY87z+Rl2R2j2MJdQDCCqAcxp9xTdhQJs9zf6cM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 5.2 108/143] lib: logic_pio: Avoid possible overlap for unregistering regions Date: Wed, 4 Sep 2019 19:54:11 +0200 Message-Id: <20190904175318.625979109@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry commit 0a27142bd1ee259e24a0be2b0133e5ca5df8da91 upstream. The code was originally written to not support unregistering logical PIO regions. To accommodate supporting unregistering logical PIO regions, subtly modify LOGIC_PIO_CPU_MMIO region registration code, such that the "end" of the registered regions is the "end" of the last region, and not the sum of the sizes of all the registered regions. Cc: stable@vger.kernel.org Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- lib/logic_pio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -35,7 +35,7 @@ int logic_pio_register_range(struct logi struct logic_pio_hwaddr *range; resource_size_t start; resource_size_t end; - resource_size_t mmio_sz = 0; + resource_size_t mmio_end = 0; resource_size_t iio_sz = MMIO_UPPER_LIMIT; int ret = 0; @@ -56,7 +56,7 @@ int logic_pio_register_range(struct logi /* for MMIO ranges we need to check for overlap */ if (start >= range->hw_start + range->size || end < range->hw_start) { - mmio_sz += range->size; + mmio_end = range->io_start + range->size; } else { ret = -EFAULT; goto end_register; @@ -69,16 +69,16 @@ int logic_pio_register_range(struct logi /* range not registered yet, check for available space */ if (new_range->flags == LOGIC_PIO_CPU_MMIO) { - if (mmio_sz + new_range->size - 1 > MMIO_UPPER_LIMIT) { + if (mmio_end + new_range->size - 1 > MMIO_UPPER_LIMIT) { /* if it's too big check if 64K space can be reserved */ - if (mmio_sz + SZ_64K - 1 > MMIO_UPPER_LIMIT) { + if (mmio_end + SZ_64K - 1 > MMIO_UPPER_LIMIT) { ret = -E2BIG; goto end_register; } new_range->size = SZ_64K; pr_warn("Requested IO range too big, new size set to 64K\n"); } - new_range->io_start = mmio_sz; + new_range->io_start = mmio_end; } else if (new_range->flags == LOGIC_PIO_INDIRECT) { if (iio_sz + new_range->size - 1 > IO_SPACE_LIMIT) { ret = -E2BIG;