From patchwork Wed Sep 4 16:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 172938 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp162340ilq; Wed, 4 Sep 2019 09:33:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXwCDh2edX3e4VVWW+4rvBgHFwRRzMQiQWgGQcLua8I5s7RUSyeMJWo/L40CCnTR9oaXCu X-Received: by 2002:aa7:9e05:: with SMTP id y5mr27700946pfq.38.1567614801715; Wed, 04 Sep 2019 09:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567614801; cv=none; d=google.com; s=arc-20160816; b=s4Wskyv6roT3A8TkuG660Mn/y12LVqA+A4/i3kfG50AN86kAom90v2gPKzP65XHM4t EjkDONzKBuhmDpnmfTMYnAlDdNHugxD5A1XH9dIj53CsshRJtQeGfnuVrN1keZ/INdEs jjsuDOoeYHhcmJUXO2DO95wuBk9NGzdOhoXojVmSQq4kYiFW3qmOXiB1YrotPx8NNGb1 vGg6GG4LMoLRP2LCyeIz1kU8l8ye8lfUHWuxiVuqR+J0+SJtTZunLQ7MSh/Va7hbThUk 0z3J2RK1PoUAtWsloKQqjTmQjtXd7u7Awj1GY2g/NB+1JhDTnGn5ApHIM4p0rPTHR697 rIEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=Fp2YCXZXi86iVBoHa0/O9dAkaH4gZxntiCmBxmYv0Mg=; b=B2EM9yiRWALO3awQd3fQUVcd0C3NjwC/lT+2YnP4z10bIPbe22U9uPl0Mdn9SxSmM2 G/0so/SMA6Eg44TpsELBcbgwOcDqq9bsSLkEsid77lJ/60DSqTH8UsKJZVnjZYrbLARy qDohVkw4BtxPt43Nps4x6IJS0cM8U3EM5w1Nt1jzTM64GlJKVKzamXba2G0fa192mpZV 2YUP0TVw+eBf2M+410a5aXG0CjP1TuiWDsfcXANMv68FoJrGizQZiemlK81h5eZa6aEt yPVhNLgUlBjHTIYH+/DRVo+BtjXMSGhtl6S7h8nRVNgA7bg5SBSdPVWH/vlNir8O/23p vEBQ== 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 d23si2654331pjw.17.2019.09.04.09.33.21; Wed, 04 Sep 2019 09:33:21 -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 S1731782AbfIDQdU (ORCPT + 28 others); Wed, 4 Sep 2019 12:33:20 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:51104 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731520AbfIDQdU (ORCPT ); Wed, 4 Sep 2019 12:33:20 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A280621E8953A5A2F875; Thu, 5 Sep 2019 00:33:15 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 5 Sep 2019 00:33:06 +0800 From: John Garry To: CC: , , , , , John Garry Subject: [PATCH] lib: logic_pio: Enforce LOGIC_PIO_INDIRECT region ops are set at registration Date: Thu, 5 Sep 2019 00:30:33 +0800 Message-ID: <1567614633-210580-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 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 accessors ops prior to registration, enforce the check for these 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 --- I hope that the soc maintainers don't mind taking this patch through their tree, as it is relevant to the HiSilicon LPC bus driver. Thanks -- 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 \