From patchwork Wed Sep 4 17:54:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 172959 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp274990ilq; Wed, 4 Sep 2019 11:16:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxN0k8iVK+dXMS62yyc6sAv1FZjVgP/d9Ild4YKxe0Ef2c+3TclY1fSf1Tm77Y4Mn4WsVj X-Received: by 2002:a17:90a:9907:: with SMTP id b7mr6481441pjp.101.1567620969133; Wed, 04 Sep 2019 11:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620969; cv=none; d=google.com; s=arc-20160816; b=csy+Exd9YEki3FKf+ipQ6ACWCTspjmBBJ9mFHeiYjCdcjLnU+3SKzT7l8Udr88UH+I hTLFMH9zRXUG4KJktqrLMnopp6AHKBCHzEa74ofi9Yw4eVHJtsc1cG4Q52hr5KKyZXcD kaHObl6tdqcLeEeoTT23FgIjbKAp2srb4Hh7zAhCl5eUtacoDOCixGrC59zZyUj0YY4Q Tc31ykObDuis21k2Vx6hBLhYm3M7H240peD5CUnphQ6uo9t+3qtLYiRdRdsj8+AJdboE 4NIqBeKGlY8+MeaoVCSN1QOE4vHBABQLtafLhXw8G07i9IAE+NodEBmHuv/LKWaRDBy2 64EQ== 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 i6si2874654pjs.13.2019.09.04.11.16.05; Wed, 04 Sep 2019 11:16:09 -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 S2391012AbfIDSPs (ORCPT + 28 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 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;