Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0A2BC433EF for ; Sat, 8 Jan 2022 10:37:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234044AbiAHKh6 (ORCPT ); Sat, 8 Jan 2022 05:37:58 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:57084 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231232AbiAHKh5 (ORCPT ); Sat, 8 Jan 2022 05:37:57 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 567B0B8074D for ; Sat, 8 Jan 2022 10:37:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03C30C36AE5; Sat, 8 Jan 2022 10:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641638275; bh=TgiExzQYT7E5hlkoyGhgsfsCKWKWd3FY1bDyb5egQbE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tfw63Vy5Hgr12/12qbOm7haq7wb/mj9b1LVwjXV6B7gxKuKWh7AaAebVM/DPVxTVj yPE98SMXVijtTRUQkBVePvT5wXeeX0Vg2EPMn2mn5QuwUMAz/kJlLSMy5iWLIllhF6 rvSoX1UOcTfOWShiw4IviWnt7Byo3PJOfFe6oOYO73iar+M3Udjov28zszvJx+vcxi kflCYt5I+1s5903dogyRw7nLf2jOOrZt/Y06Yoy63VswbvOlCESPNrwWEioG2T+pKw ZowSweFiOk4viVQnRf8qV7BiQk87ux/5nNLTNN4kX/1RfICTWcerkDzkbWLij6+xRy r/91nDVdtDneA== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n696e-00Gk3l-Nl; Sat, 08 Jan 2022 10:37:52 +0000 Date: Sat, 08 Jan 2022 10:37:52 +0000 Message-ID: <87tueetsvz.wl-maz@kernel.org> From: Marc Zyngier To: Qianggui Song Cc: Thomas Gleixner , Kevin Hilman , Neil Armstrong , Jerome Brunet , Martin Blumenstingl , , , Subject: Re: [PATCH 2/4] irqchip/meson-gpio: support more than 8 channels gpio irq line In-Reply-To: <20220108084218.31877-3-qianggui.song@amlogic.com> References: <20220108084218.31877-1-qianggui.song@amlogic.com> <20220108084218.31877-3-qianggui.song@amlogic.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: qianggui.song@amlogic.com, tglx@linutronix.de, khilman@baylibre.com, narmstrong@baylibre.com, jbrunet@baylibre.com, martin.blumenstingl@googlemail.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 08 Jan 2022 08:42:16 +0000, Qianggui Song wrote: > > Current meson gpio irqchip driver only support 8 channels for gpio irq > line, later chips may have more then 8 channels, so need to modify code > to support more. > > Signed-off-by: Qianggui Song > --- > drivers/irqchip/irq-meson-gpio.c | 33 +++++++++++++++++++++++--------- > 1 file changed, 24 insertions(+), 9 deletions(-) > > diff --git a/drivers/irqchip/irq-meson-gpio.c b/drivers/irqchip/irq-meson-gpio.c > index d90ff0b92480..6a7b4fb13452 100644 > --- a/drivers/irqchip/irq-meson-gpio.c > +++ b/drivers/irqchip/irq-meson-gpio.c > @@ -16,7 +16,6 @@ > #include > #include > > -#define NUM_CHANNEL 8 > #define MAX_INPUT_MUX 256 > > #define REG_EDGE_POL 0x00 > @@ -60,6 +59,7 @@ struct irq_ctl_ops { > > struct meson_gpio_irq_params { > unsigned int nr_hwirq; > + unsigned int channel_num; For consistency, please name this nr_channels. > bool support_edge_both; > unsigned int edge_both_offset; > unsigned int edge_single_offset; > @@ -81,6 +81,7 @@ struct meson_gpio_irq_params { > .edge_single_offset = 0, \ > .pol_low_offset = 16, \ > .pin_sel_mask = 0xff, \ > + .channel_num = 8, \ > > #define INIT_MESON_A1_COMMON_DATA(irqs) \ > INIT_MESON_COMMON(irqs, meson_a1_gpio_irq_init, \ > @@ -90,6 +91,7 @@ struct meson_gpio_irq_params { > .edge_single_offset = 8, \ > .pol_low_offset = 0, \ > .pin_sel_mask = 0x7f, \ > + .channel_num = 8, \ > > static const struct meson_gpio_irq_params meson8_params = { > INIT_MESON8_COMMON_DATA(134) > @@ -136,8 +138,9 @@ static const struct of_device_id meson_irq_gpio_matches[] = { > struct meson_gpio_irq_controller { > const struct meson_gpio_irq_params *params; > void __iomem *base; > - u32 channel_irqs[NUM_CHANNEL]; > - DECLARE_BITMAP(channel_map, NUM_CHANNEL); > + u32 *channel_irqs; > + unsigned long *channel_map; > + u8 channel_num; Same thing. Though this is completely superfluous, see below. > spinlock_t lock; > }; > > @@ -207,8 +210,8 @@ meson_gpio_irq_request_channel(struct meson_gpio_irq_controller *ctl, > spin_lock_irqsave(&ctl->lock, flags); > > /* Find a free channel */ > - idx = find_first_zero_bit(ctl->channel_map, NUM_CHANNEL); > - if (idx >= NUM_CHANNEL) { > + idx = find_first_zero_bit(ctl->channel_map, ctl->channel_num); > + if (idx >= ctl->channel_num) { > spin_unlock_irqrestore(&ctl->lock, flags); > pr_err("No channel available\n"); > return -ENOSPC; > @@ -447,13 +450,25 @@ static int meson_gpio_irq_parse_dt(struct device_node *node, struct meson_gpio_i > > ctl->params = match->data; > > + ctl->channel_num = ctl->params->channel_num; Since you already have a pointer to params, why do you need to duplicate this information? > + ctl->channel_irqs = kcalloc(ctl->channel_num, > + sizeof(*ctl->channel_irqs), GFP_KERNEL); > + if (!ctl->channel_irqs) > + return -ENOMEM; > + > + ctl->channel_map = bitmap_zalloc(ctl->params->channel_num, GFP_KERNEL); > + if (!ctl->channel_map) { > + kfree(ctl->channel_irqs); > + return -ENOMEM; > + } > + > ret = of_property_read_variable_u32_array(node, > "amlogic,channel-interrupts", > ctl->channel_irqs, > - NUM_CHANNEL, > - NUM_CHANNEL); > + ctl->channel_num, > + ctl->channel_num); > if (ret < 0) { > - pr_err("can't get %d channel interrupts\n", NUM_CHANNEL); > + pr_err("can't get %d channel interrupts\n", ctl->channel_num); > return ret; You are now leaking the bitmap and channel_map allocations. M. -- Without deviation from the norm, progress is not possible.