From patchwork Mon Jun 24 14:35:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167597 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4311664ilk; Mon, 24 Jun 2019 07:36:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxb8pJWs+oMpnm2V/qRhFYGuFzCOCG/APth38m5Q8AG4Mqjn0pdDcp/xMZs2dhdOOXMZVL X-Received: by 2002:a17:902:b70f:: with SMTP id d15mr64394981pls.318.1561387005796; Mon, 24 Jun 2019 07:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387005; cv=none; d=google.com; s=arc-20160816; b=le7rnO12HLOnWyXLu7tB5OONI8Ck5HHo3LnUjFlZrP4vEastBMzbO02oxulrcA43A0 nbvgEcgY0IdeqalLU2HWCUfZJpPbDVlSbCmGZFXoziAttGiH2MydTrAokyFzbcPbfuVO KQBzJaAdGntmuz/bFL9kh1KflPtuo6X7MGbTjipRrGEiLBOnKt4b54KFhpTkR0KZbNRe cfDkirWFjUi98AsoLdRYak9m8pyuNH6l8MB1gR7SiIRuGKdwFSeuk1GLw0TPO1/HchhA MoT3QG9fsKYsnfnOYAGtm0HYN9zIRgMdnEnecPFpoCx1ZSbEy57hZ2LIq+0wUxOLqGby 9Mbw== 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=OpJU7uJo3GX7afAAcEYz3oDNKK2QelsMLaehetq1p+o=; b=vduLeKQfO883RE+5M4/8uKYwsdsEaZHWiHxfUhy7KkpZhi12zf6lAshpa+NSn3AgWd XzrbKQtfJQR/YKcBAI0IMWZSIL0jPkNxe+ajC4rT31QhxQCDygWtBjFkhC80FdXjmwKe 1TLgvak20LN85Z1PyKXXkdlDAcIcArRSTTaTulKqQimAu7Lp1yqe0ZJEJ6+OGMMQbwGe tpoH23Fv6c+ynp5Qv93eTqAoZv2rUWNgZ06m+qrpdAob5GXvJmH/D0nYtztZe0k4hsJf LGLeNxqjGa9S0F9OAp9E4h2Yx8FMPdf6rfsmvLLIWJbdHwgz5ExcXxyIVbDaCHdn5qhH waHw== 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 t23si11097668pjw.56.2019.06.24.07.36.45; Mon, 24 Jun 2019 07:36:45 -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 S1728950AbfFXOgo (ORCPT + 30 others); Mon, 24 Jun 2019 10:36:44 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33260 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727520AbfFXOgj (ORCPT ); Mon, 24 Jun 2019 10:36:39 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3B08A24D32A7364DE355; 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:27 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH v2 1/6] lib: logic_pio: Fix RCU usage Date: Mon, 24 Jun 2019 22:35:03 +0800 Message-ID: <1561386908-31884-2-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 traversing of io_range_list with list_for_each_entry_rcu() is not properly protected by rcu_read_lock() and rcu_read_unlock(), so add them. These functions mark the critical section scope where the list is protected for the reader, it cannot be "reclaimed". Any updater - in this case, the logical PIO registration functions - cannot update the list until the reader exits this critical section. In addition, the list traversing used in logic_pio_register_range() does not need to use the rcu variant. This is because we are already using io_range_mutex to guarantee mutual exclusion from mutating the list. Fixes: 031e3601869c ("lib: Add generic PIO mapping method") Signed-off-by: John Garry --- lib/logic_pio.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/lib/logic_pio.c b/lib/logic_pio.c index feea48fd1a0d..761296376fbc 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -46,7 +46,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) end = new_range->hw_start + new_range->size; mutex_lock(&io_range_mutex); - list_for_each_entry_rcu(range, &io_range_list, list) { + list_for_each_entry(range, &io_range_list, list) { if (range->fwnode == new_range->fwnode) { /* range already there */ goto end_register; @@ -108,26 +108,38 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) */ struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode) { - struct logic_pio_hwaddr *range; + struct logic_pio_hwaddr *range, *found_range = NULL; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { - if (range->fwnode == fwnode) - return range; + if (range->fwnode == fwnode) { + found_range = range; + break; + } } - return NULL; + rcu_read_unlock(); + + return found_range; } /* Return a registered range given an input PIO token */ static struct logic_pio_hwaddr *find_io_range(unsigned long pio) { - struct logic_pio_hwaddr *range; + struct logic_pio_hwaddr *range, *found_range = NULL; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { - if (in_range(pio, range->io_start, range->size)) - return range; + if (in_range(pio, range->io_start, range->size)) { + found_range = range; + break; + } } - pr_err("PIO entry token %lx invalid\n", pio); - return NULL; + rcu_read_unlock(); + + if (!found_range) + pr_err("PIO entry token 0x%lx invalid\n", pio); + + return found_range; } /** @@ -180,14 +192,23 @@ unsigned long logic_pio_trans_cpuaddr(resource_size_t addr) { struct logic_pio_hwaddr *range; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { if (range->flags != LOGIC_PIO_CPU_MMIO) continue; - if (in_range(addr, range->hw_start, range->size)) - return addr - range->hw_start + range->io_start; + if (in_range(addr, range->hw_start, range->size)) { + unsigned long cpuaddr; + + cpuaddr = addr - range->hw_start + range->io_start; + + rcu_read_unlock(); + return cpuaddr; + } } - pr_err("addr %llx not registered in io_range_list\n", - (unsigned long long) addr); + rcu_read_unlock(); + + pr_err("addr %pa not registered in io_range_list\n", &addr); + return ~0UL; } 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; From patchwork Mon Jun 24 14:35:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167599 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4311874ilk; Mon, 24 Jun 2019 07:36:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoMRZ7UU2j576qVJTm0LKUx7o0f9ZxhrwCpxRXjQ7Hc1QYy3oB4aspB7EJkGxRcK8ZSqS2 X-Received: by 2002:a17:902:102c:: with SMTP id b41mr97498629pla.204.1561387016957; Mon, 24 Jun 2019 07:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387016; cv=none; d=google.com; s=arc-20160816; b=DpvwWu/cDhfrJDYBkOKN1IRrpRbI1R+F7NHmIlBhxaU4KMH0GyN+NGtbOXE9gZ9aV8 xdG7w3DV3gkYiQvKId146uJ3Y5SCf/pNNyanJsqv9PqdjVfdb8a9S27bFL+RO6UjF65C 3fd0Vi+EKanupoT3iKBnphWVGrypqnlMClIkvQmpwOonz8y7na+QJyOFlDJz/8ydYOv3 d/pgTJist+o52uZUr8+ytSLKk0ZVOJbOHl4/VNeeXuliUjb9k0r4yPmLTjhgg9qTyF7A NAQ1Dobk9aOcflKsAdIpnsUISSfz6jSNzhPmmfmQCgbdDG+jdLweyPdZX3HkSNrBwSaM YvtA== 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=ZrEG8o34TAZKcyMewnNA9kGmfUhEFU6mWpLliqmz2lI=; b=NpPSVuw3rcmEriNBaoTGEy7NsieR/TryuiAPhXdidUw3785XEL2OMBDnR8heda6OTe mq4HjJGwcK6SQKeW2d5BQ1NCt/IIQyrJSyJcih7FfIgvmD5RbWBbjAQXXgAdzB+0s0w5 pAEPqjrjMCy0/SPd9XM+KUDAyvIQiv7cDzsxSw6leUR3lkkfXOZbcMr5wL8+Ru37il2B 9VqI6gyRICIdSyTOseygtYtJRimABeiLzKm7j0tEEATTwSvN9cX1QiKMhM2Ya1wso29N rQ9UxUbqXUaWRC1i0onvA7SpYe/bTsQvN1aAjKftMc27fdsCYB2WNSIq2/xyC70s2LeV wI2Q== 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 v8si10531360plg.122.2019.06.24.07.36.56; Mon, 24 Jun 2019 07:36:56 -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 S1728360AbfFXOgk (ORCPT + 30 others); Mon, 24 Jun 2019 10:36:40 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:19067 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727627AbfFXOgj (ORCPT ); Mon, 24 Jun 2019 10:36:39 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 116C6F2CF14767A30AAD; 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 3/6] lib: logic_pio: Add logic_pio_unregister_range() Date: Mon, 24 Jun 2019 22:35:05 +0800 Message-ID: <1561386908-31884-4-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 Add a function to unregister a logical PIO range. Logical PIO space can still be leaked when unregistering certain LOGIC_PIO_CPU_MMIO regions, but this acceptable for now since there are no callers to unregister LOGIC_PIO_CPU_MMIO regions, and the logical PIO region allocation scheme would need significant work to improve this. Signed-off-by: John Garry --- include/linux/logic_pio.h | 1 + lib/logic_pio.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) -- 2.17.1 diff --git a/include/linux/logic_pio.h b/include/linux/logic_pio.h index cbd9d8495690..88e1e6304a71 100644 --- a/include/linux/logic_pio.h +++ b/include/linux/logic_pio.h @@ -117,6 +117,7 @@ struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode); unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode, resource_size_t hw_addr, resource_size_t size); int logic_pio_register_range(struct logic_pio_hwaddr *newrange); +void logic_pio_unregister_range(struct logic_pio_hwaddr *range); resource_size_t logic_pio_to_hwaddr(unsigned long pio); unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr); diff --git a/lib/logic_pio.c b/lib/logic_pio.c index d0165c88f705..905027574e5d 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -98,6 +98,20 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) return ret; } +/** + * logic_pio_unregister_range - unregister a logical PIO range for a host + * @range: pointer to the IO range which has been already registered. + * + * Unregister a previously-registered IO range node. + */ +void logic_pio_unregister_range(struct logic_pio_hwaddr *range) +{ + mutex_lock(&io_range_mutex); + list_del_rcu(&range->list); + mutex_unlock(&io_range_mutex); + synchronize_rcu(); +} + /** * find_io_range_by_fwnode - find logical PIO range for given FW node * @fwnode: FW node handle associated with logical PIO range From patchwork Mon Jun 24 14:35:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167596 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4311632ilk; Mon, 24 Jun 2019 07:36:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHgk5FhRRFk2T3NKjwinEnUAB8TU5+tAyW07yboArgSXGOXiASSr/653NNcTGrTYPMi+p1 X-Received: by 2002:a17:902:4aa3:: with SMTP id x32mr25871691pld.119.1561387004369; Mon, 24 Jun 2019 07:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387004; cv=none; d=google.com; s=arc-20160816; b=JnHSUWCj03R7SIgykW8zhBgIdCy4HJagCZASEhBd4plzTqlIo6hgEioTju2mnnBS7r TapEdiHyJnmhR9AD9v3rHMpiWeTB1uE5SDsC9na4pI2dOia6rp8uKqZopc53qm2lBUhi 8Y1Qgr/wRNkZOuSmmZksYNV5TkznepnXq24LZam1iOtPCHJs33WZXyFWEzB51UbaoHQn +lnuxUTVMxLUvFeLZxoInwhKVLqJq4uW9xrmjjtAvudme/Pw4Ci8kasiwh5G3KW84+wv w2ddKdSMiU2yNXFMexCcAFlVl6/Hu7s3NEnxDvwYYfdExYV/NbGQ5C+pjc5giFJg4jop nqiA== 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=vpQoSP2Vi2lg1x36aE5SBgCgPKw2EpZdNMWXXKdNWko=; b=DZPfN+Ov2iz5Z1ZizuE04/VlBYITjSfIUnxIaYVKesDDuFMGm712pHCS7LdPKH1VoR ckkvtd5O/zHoFGBRg+OEozHJdjP/YBXUDiCoJVnMywpojPOqKtCg0WEQjG2MFI37qufl w7vJDy1N3X0w0KDoZKz00PUCbyh9YsX3TiXIwdSDgAOBda1XVogBX7/pwQcsyU9MM860 gNQbUTBl+rcZ2yasWkC2FWiRa37xl19JRl701Cc9PkKZqMIQ2Uuxm+QpIKkLrojusOGV du3heyeTiUrJf8bJqkx7xXyyjT/0hvJFBY0MDo0XQRUL0yNPtg6MM05FQtcWnVL3U11f H5KQ== 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 m14si2983945pgb.335.2019.06.24.07.36.44; Mon, 24 Jun 2019 07:36:44 -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 S1728768AbfFXOgm (ORCPT + 30 others); Mon, 24 Jun 2019 10:36:42 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33264 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727344AbfFXOgj (ORCPT ); Mon, 24 Jun 2019 10:36:39 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 45CACF383ECDD524113B; 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 4/6] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Mon, 24 Jun 2019 22:35:06 +0800 Message-ID: <1561386908-31884-5-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 If, after registering a logical PIO range, the driver probe later fails, the logical PIO range memory will be released automatically. This causes an issue, in that the logical PIO range is not unregistered and the released range memory may be later referenced. Fix by unregistering the logical PIO range. And since we now unregister the logical PIO range for probe failure, avoid the special ordering of setting logical PIO range ops, which was the previous (poor) attempt at a safeguard against this. Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry --- drivers/bus/hisi_lpc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 19d7b6ff2f17..6d301aafcad2 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -606,24 +606,25 @@ static int hisi_lpc_probe(struct platform_device *pdev) range->fwnode = dev->fwnode; range->flags = LOGIC_PIO_INDIRECT; range->size = PIO_INDIRECT_SIZE; + range->hostdata = lpcdev; + range->ops = &hisi_lpc_ops; + lpcdev->io_host = range; ret = logic_pio_register_range(range); if (ret) { dev_err(dev, "register IO range failed (%d)!\n", ret); return ret; } - lpcdev->io_host = range; /* register the LPC host PIO resources */ if (acpi_device) ret = hisi_lpc_acpi_probe(dev); else ret = of_platform_populate(dev->of_node, NULL, NULL, dev); - if (ret) + if (ret) { + logic_pio_unregister_range(range); return ret; - - lpcdev->io_host->hostdata = lpcdev; - lpcdev->io_host->ops = &hisi_lpc_ops; + } io_end = lpcdev->io_host->io_start + lpcdev->io_host->size; dev_info(dev, "registered range [%pa - %pa]\n", From patchwork Mon Jun 24 14:35:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167602 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4312185ilk; Mon, 24 Jun 2019 07:37:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNWDwD3kN4XRPNYC/Ns7BqQAJqw8DmpVddXF6gtvSFy+rpegN97bPaahBAPwZEJn6EYVKd X-Received: by 2002:a17:90a:d587:: with SMTP id v7mr25909889pju.28.1561387031744; Mon, 24 Jun 2019 07:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387031; cv=none; d=google.com; s=arc-20160816; b=wtKWlmTukNh1BzzMdWzm1Cb5KnHOMaPWZtg8PadO3XKsp/6lgOM52CUcGTzvtQq3QP EmDV1b/YZ90jhICMwqitcZjtDpaf4ojR1f5pMIn2L5jqJna2FzJ7lxTgdtTvrfiizwyJ /nDiiHZiknHy+66I5GrjV6GnWHFIJ9DNYrpqWmfwDKiiarmOPpjx3mTxqHmhJLAO04hZ B6+zCuP8AwBOVy+ubBtBHjMt/WtYIB3oBwkfVpwx7H5XjkQZ14sYNJeDoBE+uvJYJBFq COaT+bBBoDlD3ZKNM7gE6GAAH8Hhhjr+GRbBHU/iPf9hzXItQrNHs/6Zax97b/+Ia8l6 aivQ== 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=6fNjx+D1PKPoAOqCfQ8LnMGvFndXKQKz0UlWXzBNl70=; b=vgVMfpFMmRSGwuh3jx9EGcjLsnfe9hMA6KxFHKV7EkgcMml42O71Vy+CoMHx9xLjbg Q2ImBtpSht4Bk7javxtV2TSpSSDZanS818pWc272WjtUJ35EeZvI0vg+4L1bCHcBY+TS hFL0Nug7jJnElsFBIAunNwljyWe0bot7VZfUt4bgyzwjdEJmELnR2oHe0U9BvyTpI3Qi Dl7BgQi6NEkXx/zkPIYXdgw9tw2QOZklq6+F1eHxDW8eM/oECowr5zLglTBp8qowXx0j nndyFExkPafwlEsM6zwbpVkMSnBG4Y8A1Ow/zz1TT3kTjmsJt1zwuRNc9NCo6v+7ZBNd bc8g== 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 bi3si1367662plb.226.2019.06.24.07.37.11; Mon, 24 Jun 2019 07:37:11 -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 S1729320AbfFXOhK (ORCPT + 30 others); Mon, 24 Jun 2019 10:37:10 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33262 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727607AbfFXOgk (ORCPT ); Mon, 24 Jun 2019 10:36:40 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 40541D2741A4D5A33F3C; 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 5/6] bus: hisi_lpc: Add .remove method to avoid driver unbind crash Date: Mon, 24 Jun 2019 22:35:07 +0800 Message-ID: <1561386908-31884-6-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 original driver author seemed to be under the impression that a driver cannot be removed if it does not have a .remove method. Or maybe if it is a built-in platform driver. This is not true. This crash can be created: root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1 Unable to handle kernel paging request at virtual address ffff000010035010 Mem abort info: ESR = 0x96000047 Exception class = DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000047 CM = 0, WnR = 1 swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000 [ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000 Internal error: Oops: 96000047 [#1] PREEMPT SMP Modules linked in: CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198 Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018 pstate: 20000085 (nzCv daIf -PAN -UAO) pc : hisi_lpc_target_in+0x7c/0x120 lr : hisi_lpc_target_in+0x70/0x120 sp : ffff00001efe3930 x29: ffff00001efe3930 x28: ffff841f9f599200 x27: 0000000000000002 x26: 0000000000000000 x25: 0000000000000080 x24: 00000000000000e4 x23: 0000000000000000 x22: 0000000000000064 x21: ffff801fb667d280 x20: 0000000000000001 x19: ffff00001efe39ac x18: 0000000000000000 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 x8 : ffff841febe60340 x7 : ffff801fb55c52e8 x6 : 0000000000000000 x5 : 0000000000ffc0e3 x4 : 0000000000000001 x3 : ffff801fb667d280 x2 : 0000000000000001 x1 : ffff000010035010 x0 : ffff000010035000 Call trace: hisi_lpc_target_in+0x7c/0x120 hisi_lpc_comm_in+0x88/0x98 logic_inb+0x5c/0xb8 port_inb+0x18/0x20 bt_event+0x38/0x808 smi_event_handler+0x4c/0x5a0 check_start_timer_thread.part.4+0x40/0x58 sender+0x78/0x88 smi_send.isra.6+0x94/0x108 i_ipmi_request+0x2c4/0x8f8 ipmi_request_settime+0x124/0x160 handle_send_req+0x19c/0x208 ipmi_ioctl+0x2c0/0x990 do_vfs_ioctl+0xb8/0x8f8 ksys_ioctl+0x80/0xb8 __arm64_sys_ioctl+0x1c/0x28 el0_svc_common.constprop.0+0x64/0x160 el0_svc_handler+0x28/0x78 el0_svc+0x8/0xc Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034) ---[ end trace aa842b86af7069e4 ]--- The problem here is that the host goes away but the associated logical PIO region remains registered, as do the children devices. Fix by adding a .remove method to tidy-up by removing the child devices and unregistering the logical PIO region. Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry --- drivers/bus/hisi_lpc.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 6d301aafcad2..0e9f1f141c93 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -456,6 +456,17 @@ struct hisi_lpc_acpi_cell { size_t pdata_size; }; +static void hisi_lpc_acpi_remove(struct device *hostdev) +{ + struct acpi_device *adev = ACPI_COMPANION(hostdev); + struct acpi_device *child; + + device_for_each_child(hostdev, NULL, hisi_lpc_acpi_remove_subdev); + + list_for_each_entry(child, &adev->children, node) + acpi_device_clear_enumerated(child); +} + /* * hisi_lpc_acpi_probe - probe children for ACPI FW * @hostdev: LPC host device pointer @@ -555,8 +566,7 @@ static int hisi_lpc_acpi_probe(struct device *hostdev) return 0; fail: - device_for_each_child(hostdev, NULL, - hisi_lpc_acpi_remove_subdev); + hisi_lpc_acpi_remove(hostdev); return ret; } @@ -626,6 +636,8 @@ static int hisi_lpc_probe(struct platform_device *pdev) return ret; } + dev_set_drvdata(dev, lpcdev); + io_end = lpcdev->io_host->io_start + lpcdev->io_host->size; dev_info(dev, "registered range [%pa - %pa]\n", &lpcdev->io_host->io_start, &io_end); @@ -633,6 +645,23 @@ static int hisi_lpc_probe(struct platform_device *pdev) return ret; } +static int hisi_lpc_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct acpi_device *acpi_device = ACPI_COMPANION(dev); + struct hisi_lpc_dev *lpcdev = dev_get_drvdata(dev); + struct logic_pio_hwaddr *range = lpcdev->io_host; + + if (acpi_device) + hisi_lpc_acpi_remove(dev); + else + of_platform_depopulate(dev); + + logic_pio_unregister_range(range); + + return 0; +} + static const struct of_device_id hisi_lpc_of_match[] = { { .compatible = "hisilicon,hip06-lpc", }, { .compatible = "hisilicon,hip07-lpc", }, @@ -646,5 +675,6 @@ static struct platform_driver hisi_lpc_driver = { .acpi_match_table = ACPI_PTR(hisi_lpc_acpi_match), }, .probe = hisi_lpc_probe, + .remove = hisi_lpc_remove, }; builtin_platform_driver(hisi_lpc_driver); From patchwork Mon Jun 24 14:35:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167601 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4312052ilk; Mon, 24 Jun 2019 07:37:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxq7/qetzm0N1sOAdpW86pTMNISvGIr35iXR3XgI1J8R3MpEWZcsbwi1dDANCCc0LxnQUGS X-Received: by 2002:a17:90a:ac11:: with SMTP id o17mr25605991pjq.134.1561387024842; Mon, 24 Jun 2019 07:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387024; cv=none; d=google.com; s=arc-20160816; b=P26njv9GSe1seAQSA7bNlJb3XZ9jiklRukR30d9A+qxNnp2pxtmhzdLT07vQdhPrVD /8rNeXSoiiu5dts0pU/hpIwX1OWiM6WSY4awuSMTNM7ssTLv66q88qtB9LfxcqtMyq5d 0TNxCi1rkrMTAoRJQ5FuLhQgiwjHd/x1s7urDmFW8q6cImxT86+0VWANr926tfU8SP1O DJES3m0RdAM1SipLfUMFF3FijPA1RGljoHQmjT4BuNcL5GR2H17TfubH5teQ4RhEbLES CKtoQtxOYvhrogdEdSmJAmGwxBBpIftqSqf9qKHPedx+UHQhrSoSdB4YBNozjbxIpK27 gkeA== 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=c5Qb7+GCUQbMBVYb30khBcTVFmxUrPGSa5utdoQ5VA4=; b=h1XyQ86s+DN/qqKroV2kxYajnmsNNZHnVwbI5REh6vT3/afplHBQmpUSEKUq8XTtIO LhksXILq+2iI5VSjNw+LoBq0Qs8BiXasYKTgxOV4zurzP9cu+1P0FqVscIL/J2I6jZ9/ 1nA30uXMOuFDOwNtI1kckgXjtnTxr1Ta44AasNFw7FY1gLJx2OPGx7ufRX7Aj4c+om6Z rJ6Hn8kUPA3tDrGWI+BnNsml4f4jYbFVw0b+0NyP5iBe3LAJN8ENwe5aVQO7xDY3nw6C YoE2j2qRnY/MVXtHnvFe1ki0Il3tKXduN1gbCeoey3sxAKgpKDz0TkNAKoyAzXYr5G/p HiOQ== 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 g21si9758788plo.306.2019.06.24.07.37.04; Mon, 24 Jun 2019 07:37:04 -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 S1729315AbfFXOhC (ORCPT + 30 others); Mon, 24 Jun 2019 10:37:02 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:19070 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726887AbfFXOgk (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 15FFA7B77114539C2EC5; 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:29 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH v2 6/6] lib: logic_pio: Enforce LOGIC_PIO_INDIRECT region ops are set at registration Date: Mon, 24 Jun 2019 22:35:08 +0800 Message-ID: <1561386908-31884-7-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 Since the only LOGIC_PIO_INDIRECT host (hisi-lpc) now sets the ops prior to registration, enforce this check at registration instead of in the IO port accessors to simplify and marginally optimise the code. A slight misalignment is also tidied. Suggested-by: Bjorn Helgaas Signed-off-by: John Garry --- lib/logic_pio.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/lib/logic_pio.c b/lib/logic_pio.c index 905027574e5d..52831a85293a 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -39,7 +39,8 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) resource_size_t iio_sz = MMIO_UPPER_LIMIT; int ret = 0; - if (!new_range || !new_range->fwnode || !new_range->size) + if (!new_range || !new_range->fwnode || !new_range->size || + (new_range->flags == LOGIC_PIO_INDIRECT && !new_range->ops)) return -EINVAL; start = new_range->hw_start; @@ -237,7 +238,7 @@ type logic_in##bw(unsigned long addr) \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ ret = entry->ops->in(entry->hostdata, \ addr, sizeof(type)); \ else \ @@ -253,7 +254,7 @@ void logic_out##bw(type value, unsigned long addr) \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ entry->ops->out(entry->hostdata, \ addr, value, sizeof(type)); \ else \ @@ -261,7 +262,7 @@ void logic_out##bw(type value, unsigned long addr) \ } \ } \ \ -void logic_ins##bw(unsigned long addr, void *buffer, \ +void logic_ins##bw(unsigned long addr, void *buffer, \ unsigned int count) \ { \ if (addr < MMIO_UPPER_LIMIT) { \ @@ -269,7 +270,7 @@ void logic_ins##bw(unsigned long addr, void *buffer, \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ entry->ops->ins(entry->hostdata, \ addr, buffer, sizeof(type), count); \ else \ @@ -286,7 +287,7 @@ void logic_outs##bw(unsigned long addr, const void *buffer, \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ entry->ops->outs(entry->hostdata, \ addr, buffer, sizeof(type), count); \ else \