From patchwork Mon Oct 28 12:10:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 177905 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3305362ill; Mon, 28 Oct 2019 05:13:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVp8ChFQNqWmOzfwOhS4MK7YuNtmy9s0BBDxvXWgGSFZvsQrVrp0xGU1qpwPcHLuPvV9y7 X-Received: by 2002:a17:906:4a15:: with SMTP id w21mr16340314eju.294.1572264803154; Mon, 28 Oct 2019 05:13:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572264803; cv=none; d=google.com; s=arc-20160816; b=eS/yOZ5vyAaSngA4YAgoAqLjVQk0R5Z9mzNkFcCD7nsKSUsYt6ah4rx25P5B2l4GYK hFQZ4DoEV40/91MGnWRvCoRSoea4KANEgWnBYkt5Hu0+bshbLXbjaSKO3B5FO4lvHHpj 6wNthT11ZrcLXmQWiF/gzbXLd6JVJsZB/2HwMlZ+Kv1adMM1SuWCrela2hu5utjpzSRr GI7jcB/OlgcdlNXHjtYfgKR2AaZI79L3kEUAeo1/QMtZKM5p9H8wTI6I/HZQ7pFqq0aQ Upa8IJGbBPqpzjxrlUoRYoZ/E3WBDs2q7JhIutpb9t1lFP4OVyQTnWZMzdX2kVGtS+iX l04w== 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=RIE+EgOtTrp9Aw3k4CsYN7GGPkAgexAC1RqFRA/UgKU=; b=Xvi4O7hYz3qc7b1SRQVZwECY4kOohMjg+6hopZdaBHLf+DWbB640u96Cjs2PwxRVPT rqn6TUmfec0Yq/5GL9I7lWRVhbJ3sxbMGJXCvHwssNChOHBk66/N3pfjW9EzSFKTyslq 9LTr/wPR+NMcxzokie8g+ZfKDL1hDa+f9Qx7JZtYn7c2gWYh48eyqkvAb4OeeJI456Me Jl38NYlYRGK+CRzawm7+JDnBhBMK0L1fKhy9Lf+zw1leoRapYnEHKNXMTVpMLN0sd6OQ mYGtcM7FRDqt5XPnBQ06+K0GpfisSvu04/alBxmRg+5wEHH977cNVs9NZEp3bOI16fBC lQFw== 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 b50si7315256ede.28.2019.10.28.05.13.22; Mon, 28 Oct 2019 05:13:23 -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 S2388974AbfJ1MNS (ORCPT + 26 others); Mon, 28 Oct 2019 08:13:18 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:37054 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727763AbfJ1MNR (ORCPT ); Mon, 28 Oct 2019 08:13:17 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DECEAB3B245FFE113604; Mon, 28 Oct 2019 20:13:14 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Mon, 28 Oct 2019 20:13:05 +0800 From: John Garry To: CC: , , , , , John Garry Subject: [PATCH v2 1/5] lib: logic_pio: Enforce LOGIC_PIO_INDIRECT region ops are set at registration Date: Mon, 28 Oct 2019 20:10:01 +0800 Message-ID: <1572264605-172363-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1572264605-172363-1-git-send-email-john.garry@huawei.com> References: <1572264605-172363-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] 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 for accessors ops at registration instead of in the IO port accessors to simplify and marginally optimise the code. A slight misalignment is also tidied. Also add myself as an author. Suggested-by: Bjorn Helgaas Signed-off-by: John Garry --- lib/logic_pio.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/lib/logic_pio.c b/lib/logic_pio.c index 905027574e5d..f511a99bb389 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -3,6 +3,7 @@ * Copyright (C) 2017 HiSilicon Limited, All Rights Reserved. * Author: Gabriele Paoloni * Author: Zhichang Yuan + * Author: John Garry */ #define pr_fmt(fmt) "LOGIC PIO: " fmt @@ -39,7 +40,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 +239,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 +255,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 +263,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 +271,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 +288,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 \