From patchwork Thu Aug 27 14:54:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 511320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 77A071401EF for ; Fri, 28 Aug 2015 00:54:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753464AbbH0Oy4 (ORCPT ); Thu, 27 Aug 2015 10:54:56 -0400 Received: from mail-la0-f52.google.com ([209.85.215.52]:35853 "EHLO mail-la0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753495AbbH0Oyz (ORCPT ); Thu, 27 Aug 2015 10:54:55 -0400 Received: by labia3 with SMTP id ia3so14244904lab.3 for ; Thu, 27 Aug 2015 07:54:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qG7EbWRKTda+eqHVsCXRX+myRXyTxzujDr9/Ea0ePus=; b=Qs6K7iZcDE+Qkj+PSonPxuuo3vxWIbf3w5Mj7f/6ZBz/VdKWUhZq6q4t2W5jFcjmu6 AYu6G+MHn1sukSNyO8j+2T3W2LSMDEXYYnvFfkV8WnLdEynGSlhnvPhzSy2adIfeRhvn f0dO/gWkbO4RVhFhGtFaTQavTDQevFE+UAHbJYJc9dJbrwG3pO92DDKtzA6dHu421IH/ W8/nZMmtM948kT5oJ8zQ8ga9/L2Mz32UkI/QIvySqfqziXw9DwdErLIZunJPCB5Kk3kU CheubSMc0Y1tLorenaeZcBu0dXL19bT8b32bAwGdniQ0FNxCk3721pvabMDmGUqGqTx/ jNDw== X-Gm-Message-State: ALoCoQmb3ZZgDNQNIsr19WjS09rosK4Od4E8t7d+nJirfabrCrPdJkbP+3mL2v1HPGJZrR+/xEZh X-Received: by 10.112.205.6 with SMTP id lc6mr2366954lbc.95.1440687294353; Thu, 27 Aug 2015 07:54:54 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by smtp.gmail.com with ESMTPSA id ut5sm641800lbc.33.2015.08.27.07.54.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Aug 2015 07:54:53 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Tien Hock Loh Cc: Alexandre Courbot , Linus Walleij Subject: [PATCH 2/5] gpio: altera: use container_of() to get state container Date: Thu, 27 Aug 2015 16:54:48 +0200 Message-Id: <1440687288-17037-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The state container of the Altera GPIO driver is extracted from the gpio_chip exploiting the fact that offsetof() the struct gpio_chip inside the struct of_mm_gpio_chip are both 0, so the container_of() is in practice a noop. However if a member is added to struct altera_gpio_chip in front of struct of_mm_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. Cc: Tien Hock Loh Signed-off-by: Linus Walleij --- drivers/gpio/gpio-altera.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-altera.c b/drivers/gpio/gpio-altera.c index 9b7e0b3db387..9087647e765a 100644 --- a/drivers/gpio/gpio-altera.c +++ b/drivers/gpio/gpio-altera.c @@ -42,6 +42,11 @@ struct altera_gpio_chip { int mapped_irq; }; +static struct altera_gpio_chip *to_altera(struct gpio_chip *gc) +{ + return container_of(gc, struct altera_gpio_chip, mmchip.gc); +} + static void altera_gpio_irq_unmask(struct irq_data *d) { struct altera_gpio_chip *altera_gc; @@ -49,7 +54,7 @@ static void altera_gpio_irq_unmask(struct irq_data *d) unsigned long flags; u32 intmask; - altera_gc = irq_data_get_irq_chip_data(d); + altera_gc = to_altera(irq_data_get_irq_chip_data(d)); mm_gc = &altera_gc->mmchip; spin_lock_irqsave(&altera_gc->gpio_lock, flags); @@ -67,7 +72,7 @@ static void altera_gpio_irq_mask(struct irq_data *d) unsigned long flags; u32 intmask; - altera_gc = irq_data_get_irq_chip_data(d); + altera_gc = to_altera(irq_data_get_irq_chip_data(d)); mm_gc = &altera_gc->mmchip; spin_lock_irqsave(&altera_gc->gpio_lock, flags); @@ -87,7 +92,7 @@ static int altera_gpio_irq_set_type(struct irq_data *d, { struct altera_gpio_chip *altera_gc; - altera_gc = irq_data_get_irq_chip_data(d); + altera_gc = to_altera(irq_data_get_irq_chip_data(d)); if (type == IRQ_TYPE_NONE) return 0; @@ -211,7 +216,7 @@ static void altera_gpio_irq_edge_handler(unsigned int irq, unsigned long status; int i; - altera_gc = irq_desc_get_handler_data(desc); + altera_gc = to_altera(irq_desc_get_handler_data(desc)); chip = irq_desc_get_chip(desc); mm_gc = &altera_gc->mmchip; irqdomain = altera_gc->mmchip.gc.irqdomain; @@ -241,7 +246,7 @@ static void altera_gpio_irq_leveL_high_handler(unsigned int irq, unsigned long status; int i; - altera_gc = irq_desc_get_handler_data(desc); + altera_gc = to_altera(irq_desc_get_handler_data(desc)); chip = irq_desc_get_chip(desc); mm_gc = &altera_gc->mmchip; irqdomain = altera_gc->mmchip.gc.irqdomain;