From patchwork Thu Aug 27 14:55:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 52771 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 7135B22EA3 for ; Thu, 27 Aug 2015 14:56:07 +0000 (UTC) Received: by wicbi2 with SMTP id bi2sf18830262wic.3 for ; Thu, 27 Aug 2015 07:56:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=rAIAhYBziIYj2/bpRBIZdkNSK+296yJtZE+H4SXVP8M=; b=EM9Wm3XjTVIU1sA/OMKuMHygorXKV0hWBaxEE9bQ/2hyRxQJMtV/qdBMwS7EYte4r4 keqnTvcA30wiRPFMT7WOnOH/uA3GJXVABgBS/ki7jhgQxJ4Gfk5ao9sQwi2e3/XlcmBK +C+yK4RCdOg7LyWjy0qQa4Qf4OOIOGEOV3n28raLvHuc9wNg9YOk+6FUb/AuIJj9N3oz uTTBvAwjQrVXvPZjoxT+EBXqfN20d+sFj37l2rldzVa4MPnYkvW9Mjtcn5p9gOZUBK6V wnyzDHFhsuz0juNeFB1MWyFdFmOYlFr4VH0fmHwnncut9sFIozKzpaKPxZ/2TV8G73AD /xxQ== X-Gm-Message-State: ALoCoQmKyr0iSs8i2emweb41n+qo/u9y0JI22zwsG2vB6tNGMm0/nOSf54sikQwlZQaxem8c/4Tx X-Received: by 10.180.89.104 with SMTP id bn8mr4267269wib.4.1440687366682; Thu, 27 Aug 2015 07:56:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.202 with SMTP id p10ls85983lae.95.gmail; Thu, 27 Aug 2015 07:56:06 -0700 (PDT) X-Received: by 10.112.170.129 with SMTP id am1mr2503458lbc.116.1440687366532; Thu, 27 Aug 2015 07:56:06 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id bj8si2426757lbc.93.2015.08.27.07.56.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Aug 2015 07:56:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by laba3 with SMTP id a3so14312788lab.1 for ; Thu, 27 Aug 2015 07:56:06 -0700 (PDT) X-Received: by 10.112.63.138 with SMTP id g10mr2484299lbs.106.1440687366422; Thu, 27 Aug 2015 07:56:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp4701135lbb; Thu, 27 Aug 2015 07:56:05 -0700 (PDT) X-Received: by 10.68.205.232 with SMTP id lj8mr7292229pbc.116.1440687363804; Thu, 27 Aug 2015 07:56:03 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qw6si4086460pab.207.2015.08.27.07.56.02; Thu, 27 Aug 2015 07:56:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753554AbbH0O4C (ORCPT + 2 others); Thu, 27 Aug 2015 10:56:02 -0400 Received: from mail-la0-f53.google.com ([209.85.215.53]:36799 "EHLO mail-la0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752960AbbH0O4B (ORCPT ); Thu, 27 Aug 2015 10:56:01 -0400 Received: by labia3 with SMTP id ia3so14268876lab.3 for ; Thu, 27 Aug 2015 07:55:59 -0700 (PDT) X-Received: by 10.112.160.73 with SMTP id xi9mr2446723lbb.92.1440687359587; Thu, 27 Aug 2015 07:55:59 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by smtp.gmail.com with ESMTPSA id jg8sm647551lbc.14.2015.08.27.07.55.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Aug 2015 07:55:58 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Stefan Agner Cc: Alexandre Courbot , Linus Walleij Subject: [PATCH 4/5] gpio: vf610: use container_of() to get state container Date: Thu, 27 Aug 2015 16:55:55 +0200 Message-Id: <1440687355-17157-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-gpio@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The state container of the vf610 GPIO driver is sometimes extracted from the gpio_chip exploiting the fact that offsetof() the struct gpio_chip inside the struct vf610_gpio_port is 0, so the container_of() is in practice a noop. However if a member is added to struct vf610_gpio_port in front of struct gpio_chip, things will break. Using proper container_of() avoids this problem. Semantically this is a noop, the compiler will optimize it away, but syntactically it makes me happier. Also replace some explicit container_of() calls with the helper function. Cc: Stefan Agner Signed-off-by: Linus Walleij --- drivers/gpio/gpio-vf610.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c index 3d5714d4f405..f0d78f6cc991 100644 --- a/drivers/gpio/gpio-vf610.c +++ b/drivers/gpio/gpio-vf610.c @@ -62,6 +62,11 @@ struct vf610_gpio_port { static struct irq_chip vf610_gpio_irq_chip; +static struct vf610_gpio_port *to_vf610_gp(struct gpio_chip *gc) +{ + return container_of(gc, struct vf610_gpio_port, gc); +} + static const struct of_device_id vf610_gpio_dt_ids[] = { { .compatible = "fsl,vf610-gpio" }, { /* sentinel */ } @@ -89,16 +94,14 @@ static void vf610_gpio_free(struct gpio_chip *chip, unsigned offset) static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) { - struct vf610_gpio_port *port = - container_of(gc, struct vf610_gpio_port, gc); + struct vf610_gpio_port *port = to_vf610_gp(gc); return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio)); } static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) { - struct vf610_gpio_port *port = - container_of(gc, struct vf610_gpio_port, gc); + struct vf610_gpio_port *port = to_vf610_gp(gc); unsigned long mask = BIT(gpio); if (val) @@ -122,7 +125,8 @@ static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, static void vf610_gpio_irq_handler(u32 irq, struct irq_desc *desc) { - struct vf610_gpio_port *port = irq_desc_get_handler_data(desc); + struct vf610_gpio_port *port = + to_vf610_gp(irq_desc_get_handler_data(desc)); struct irq_chip *chip = irq_desc_get_chip(desc); int pin; unsigned long irq_isfr; @@ -142,7 +146,8 @@ static void vf610_gpio_irq_handler(u32 irq, struct irq_desc *desc) static void vf610_gpio_irq_ack(struct irq_data *d) { - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); + struct vf610_gpio_port *port = + to_vf610_gp(irq_data_get_irq_chip_data(d)); int gpio = d->hwirq; vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR); @@ -150,7 +155,8 @@ static void vf610_gpio_irq_ack(struct irq_data *d) static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type) { - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); + struct vf610_gpio_port *port = + to_vf610_gp(irq_data_get_irq_chip_data(d)); u8 irqc; switch (type) { @@ -185,7 +191,8 @@ static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type) static void vf610_gpio_irq_mask(struct irq_data *d) { - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); + struct vf610_gpio_port *port = + to_vf610_gp(irq_data_get_irq_chip_data(d)); void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); vf610_gpio_writel(0, pcr_base); @@ -193,7 +200,8 @@ static void vf610_gpio_irq_mask(struct irq_data *d) static void vf610_gpio_irq_unmask(struct irq_data *d) { - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); + struct vf610_gpio_port *port = + to_vf610_gp(irq_data_get_irq_chip_data(d)); void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET, @@ -202,7 +210,8 @@ static void vf610_gpio_irq_unmask(struct irq_data *d) static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) { - struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d); + struct vf610_gpio_port *port = + to_vf610_gp(irq_data_get_irq_chip_data(d)); if (enable) enable_irq_wake(port->irq);