From patchwork Fri Jan 30 10:45:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 44035 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 ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6F5EB20CA8 for ; Fri, 30 Jan 2015 10:51:49 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id n3sf42035wiv.0 for ; Fri, 30 Jan 2015 02:51:43 -0800 (PST) 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=g0m3+48j0nMRGvo1/lDQi5jdHIFgqJMvr6vamBZCQEo=; b=farf85cc/Cou9tIvbjZtXw048jtJUyK1sWogof16bl0e5/TDR0fLSE1Ai5IxLDOlKy utYCmU6+YxhB3M2CK3OHk6/O6dNNR3/Tp+MLpXxWN/fyTV/tlBSXju8OJvTb1kWMzroB iZNH+3skSDLMVs4ZEb4uaWv66ERcFto1USsjTkL1WB/cM1Ka3ajzpvp+CTpBlpxM2/Vk Ped6FHi+1xHYHyvBJhguOgBrQoTOJs7mnhRZi6pCCB/sA3/EeK5kd0URu3AkvB9qBWo6 sibOX/gjrhRsAOhCOEL3iEmX07WHM2SQX/7NxElGN5Hqjk9/P6R8IctarvObeFBurHxX xb1Q== X-Gm-Message-State: ALoCoQk3n/mlqTA9M9sfMQo1vN+MCkdEdOR7QEgjVddH+HtFe5wo+Kf7MRbFqfq+9ZaPHeqn7oO9 X-Received: by 10.180.81.131 with SMTP id a3mr255892wiy.1.1422614768797; Fri, 30 Jan 2015 02:46:08 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.130 with SMTP id b2ls354895laa.27.gmail; Fri, 30 Jan 2015 02:46:08 -0800 (PST) X-Received: by 10.112.92.129 with SMTP id cm1mr5616880lbb.85.1422614768640; Fri, 30 Jan 2015 02:46:08 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id x4si9852371lbm.37.2015.01.30.02.46.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 Jan 2015 02:46:08 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ge10so23008465lab.10 for ; Fri, 30 Jan 2015 02:46:08 -0800 (PST) X-Received: by 10.152.43.103 with SMTP id v7mr5736079lal.29.1422614768199; Fri, 30 Jan 2015 02:46:08 -0800 (PST) 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.35.133 with SMTP id h5csp239450lbj; Fri, 30 Jan 2015 02:46:07 -0800 (PST) X-Received: by 10.70.45.17 with SMTP id i17mr7933708pdm.13.1422614766431; Fri, 30 Jan 2015 02:46:06 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qn10si13166490pdb.256.2015.01.30.02.46.05 for ; Fri, 30 Jan 2015 02:46:06 -0800 (PST) Received-SPF: none (google.com: linux-gpio-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759176AbbA3KqE (ORCPT ); Fri, 30 Jan 2015 05:46:04 -0500 Received: from mail-lb0-f178.google.com ([209.85.217.178]:35204 "EHLO mail-lb0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753101AbbA3KqB (ORCPT ); Fri, 30 Jan 2015 05:46:01 -0500 Received: by mail-lb0-f178.google.com with SMTP id u10so35656559lbd.9 for ; Fri, 30 Jan 2015 02:45:59 -0800 (PST) X-Received: by 10.112.211.168 with SMTP id nd8mr5888946lbc.18.1422614759879; Fri, 30 Jan 2015 02:45:59 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id g5sm2647663lag.11.2015.01.30.02.45.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jan 2015 02:45:58 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Alexandre Courbot , Linus Walleij , Semen Protsenko , Mans Rullgard Subject: [PATCH 1/2] gpio: max732x: use an inline function for container cast Date: Fri, 30 Jan 2015 11:45:54 +0100 Message-Id: <1422614754-5391-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.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.51 as permitted sender) smtp.mail=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: , Cast the struct gpio_chip into a max732x_chip using an inline macro and move the assignment to the variable declaration to save lines and simplify things. Cc: Semen Protsenko Cc: Mans Rullgard Signed-off-by: Linus Walleij --- drivers/gpio/gpio-max732x.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c index 745698d977a5..a095b2393fe9 100644 --- a/drivers/gpio/gpio-max732x.c +++ b/drivers/gpio/gpio-max732x.c @@ -161,6 +161,11 @@ struct max732x_chip { #endif }; +static inline struct max732x_chip *to_max732x(struct gpio_chip *gc) +{ + return container_of(gc, struct max732x_chip, gpio_chip); +} + static int max732x_writeb(struct max732x_chip *chip, int group_a, uint8_t val) { struct i2c_client *client; @@ -199,12 +204,10 @@ static inline int is_group_a(struct max732x_chip *chip, unsigned off) static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off) { - struct max732x_chip *chip; + struct max732x_chip *chip = to_max732x(gc); uint8_t reg_val; int ret; - chip = container_of(gc, struct max732x_chip, gpio_chip); - ret = max732x_readb(chip, is_group_a(chip, off), ®_val); if (ret < 0) return 0; @@ -215,12 +218,10 @@ static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off) static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask, int val) { - struct max732x_chip *chip; + struct max732x_chip *chip = to_max732x(gc); uint8_t reg_out; int ret; - chip = container_of(gc, struct max732x_chip, gpio_chip); - mutex_lock(&chip->lock); reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; @@ -261,11 +262,9 @@ static void max732x_gpio_set_multiple(struct gpio_chip *gc, static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) { - struct max732x_chip *chip; + struct max732x_chip *chip = to_max732x(gc); unsigned int mask = 1u << off; - chip = container_of(gc, struct max732x_chip, gpio_chip); - if ((mask & chip->dir_input) == 0) { dev_dbg(&chip->client->dev, "%s port %d is output only\n", chip->client->name, off); @@ -285,11 +284,9 @@ static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) static int max732x_gpio_direction_output(struct gpio_chip *gc, unsigned off, int val) { - struct max732x_chip *chip; + struct max732x_chip *chip = to_max732x(gc); unsigned int mask = 1u << off; - chip = container_of(gc, struct max732x_chip, gpio_chip); - if ((mask & chip->dir_output) == 0) { dev_dbg(&chip->client->dev, "%s port %d is input only\n", chip->client->name, off); @@ -361,9 +358,7 @@ static void max732x_irq_update_mask(struct max732x_chip *chip) static int max732x_gpio_to_irq(struct gpio_chip *gc, unsigned off) { - struct max732x_chip *chip; - - chip = container_of(gc, struct max732x_chip, gpio_chip); + struct max732x_chip *chip = to_max732x(gc); if (chip->irq_domain) { return irq_create_mapping(chip->irq_domain,