From patchwork Wed Jun 26 16:26:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167840 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1158213ilk; Wed, 26 Jun 2019 09:28:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOhtjr2qAlstbV/So+LpT3Uoc8AVzwy3WpXOOOVg4HSUoXwJGraVqWP6Zu9UeCLiDHeA5D X-Received: by 2002:a17:902:2a69:: with SMTP id i96mr6449499plb.108.1561566523213; Wed, 26 Jun 2019 09:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561566523; cv=none; d=google.com; s=arc-20160816; b=MjXZCwe2UVN3Hw2J/UBZsZWuoSEKwIaltbW0AJZ+RllERMPzp+8TAqxKirxSnn4SfX Jdrl9pCkHhUHTBFmqBu1YJLlDMvMuKjEyMrbVPHMR/j4lqiu1SXp5jcADoTwn4qb8ZSS lAPtp6QL2Qp7oV/pPxOtzPdvZSaudAbYYlsvsYxjXPdbvWIFW5Zvf+mHSAttryKjUBjH EvDbZUcvj7MtZ4u1wRJgUqQLsWegHFpM6Ev8ECuyr3ITK7IUp9UGpyKMUTN/26zUYI9S C0suHzACoSOWSx/jee4VYXDNt69LqMIWXqyXrxgguIakK2s8IzNzLSctz0FMnG+mAZsy bFgg== 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=YMBTxzY8EMgbUWta+VfuzlgSdAGZwC8Zl2YL4QnL9t6GSMT7dk8xmfokYtO+7tW0fF eXDwyftjRxe/cQRgfhigPSnPZdtSatjAzhyvx2T4kGYZpuiAl/5lo4wQtQurPSSveGDx yccYrGSNbKp1/LxQpDS9lX6n8drJJQyl8UrwsDSLt2SEYJFvFh/fJ1ZMi79opU2OFxZu /eGsrIv7JldAjS8HuMfoSHApmeWc9OmAWsUJQ2PBUdSHndNpAUUzWRVcT00AY/bdWvzc JTeufOruOuNtGMLWljFTlGVaK9deTzCW6f3ucy9E90l2xj2DUSnaQkJkJ+7CIdlp41L6 nFJw== 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 m12si6676329pgn.149.2019.06.26.09.28.42; Wed, 26 Jun 2019 09:28:43 -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 S1726633AbfFZQ2l (ORCPT + 30 others); Wed, 26 Jun 2019 12:28:41 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:50168 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726042AbfFZQ2j (ORCPT ); Wed, 26 Jun 2019 12:28:39 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 2A0A9EADBB0639188F3A; Thu, 27 Jun 2019 00:28:31 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Thu, 27 Jun 2019 00:28:25 +0800 From: John Garry To: CC: , , , , , John Garry Subject: [PATCH v3 2/6] lib: logic_pio: Avoid possible overlap for unregistering regions Date: Thu, 27 Jun 2019 00:26:54 +0800 Message-ID: <1561566418-22714-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561566418-22714-1-git-send-email-john.garry@huawei.com> References: <1561566418-22714-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;