From patchwork Mon Jun 24 14:35:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167600 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4311973ilk; Mon, 24 Jun 2019 07:37:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqynRPg7jzSRMrAeUsXh8B0rBwvnC1tyNTYsM9ZiKoznwg7V5uHKG4Ufh2d689LvvAG8c0CP X-Received: by 2002:a17:90a:d983:: with SMTP id d3mr24842118pjv.88.1561387021678; Mon, 24 Jun 2019 07:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387021; cv=none; d=google.com; s=arc-20160816; b=QB636RZ9VnW4+Oqm4T7Y98fp2RiPJ+VRQPzflhrKAa8wVeT49yh1OH4fWJ+6u0Bjh6 D7AUvmc5uuSSm28fVJcM2zbCmcqw7Xv0uirnCqoSicpH/qpBFSNTtCxclBoN1940WnJ2 QcsH0xDy00AOY+4EfUv+Fw+334w9rFnVLYLgYqVAFoaK8pP9kHViPEe3KYnF9ODerJcv 306S/mdU/t+QltSmxyFC1fNZqVpf8eZOwlanTjZTXUfuk7sJWp7dxyqB0oMlckdV0LhB 3zQWOwhayU923QP0bJ8R4tF42lF6ySqbGTVNDk4KKtyzNxznGxPf3NWVEec9S4d9NeZf xHpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=YbMsKQOGvNVmnCkG055vw5MTKwlUSB2A0oBLuO3pDog=; b=A2SXzF2gHXbsAis50p2X3lXlWuKgwWYWpZHtLASE6R4TNd8th7N3Z6xqwV6ybFxTAz /MH1Er3hWCuU7GeHjmEtA7GRgqaM4CEesv8HW5IFwKo/pCbom+ZzuvIYJaMP3lbQ1/Wm 4wC6TfPw0rt1RTkTfKouKPuIqxsTkqLoyChZWJryScg/cvRl85zGjFx7PxP9VuI0RCbV IwWWIC/FQ4lK0ULZFn5GubyRN9NtLPRcA5yqb9m2kOsHVxa3OFtA95u6KW3mxeROPGe7 NJqX44tr3MtE8/0uIGRvLkE0Du5FAzlcqwxI23hERhb85eyQDlwSE6HXfwiUYwk2dDQG WJQg== ARC-Authentication-Results: i=1; mx.google.com; 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 b41si10485609pla.409.2019.06.24.07.37.01; Mon, 24 Jun 2019 07:37:01 -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; 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 S1729177AbfFXOg7 (ORCPT + 30 others); Mon, 24 Jun 2019 10:36:59 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:19069 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726599AbfFXOgk (ORCPT ); Mon, 24 Jun 2019 10:36:40 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 081A4A525E6CB274CEA1; Mon, 24 Jun 2019 22:36:37 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Jun 2019 22:36:28 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH v2 2/6] lib: logic_pio: Avoid possible overlap for unregistering regions Date: Mon, 24 Jun 2019 22:35:04 +0800 Message-ID: <1561386908-31884-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561386908-31884-1-git-send-email-john.garry@huawei.com> References: <1561386908-31884-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: John Garry --- lib/logic_pio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/lib/logic_pio.c b/lib/logic_pio.c index 761296376fbc..d0165c88f705 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -35,7 +35,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) 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 logic_pio_hwaddr *new_range) /* 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 logic_pio_hwaddr *new_range) /* 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;