From patchwork Thu Mar 7 08:35:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 225767 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 DE3E22C038D for ; Thu, 7 Mar 2013 19:36:07 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754809Ab3CGIgG (ORCPT ); Thu, 7 Mar 2013 03:36:06 -0500 Received: from zoneX.GCU-Squad.org ([194.213.125.0]:37404 "EHLO services.gcu-squad.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754794Ab3CGIgG (ORCPT ); Thu, 7 Mar 2013 03:36:06 -0500 Received: from jdelvare.pck.nerim.net ([62.212.121.182] helo=endymion.delvare) by services.gcu-squad.org (GCU Mailer Daemon) with esmtpsa id 1UDWIx-0002J2-8b (TLSv1:AES128-SHA:128) (envelope-from ) ; Thu, 07 Mar 2013 09:35:59 +0100 Date: Thu, 7 Mar 2013 09:35:53 +0100 From: Jean Delvare To: Peter Korsgaard Cc: Wolfram Sang , Linux I2C Subject: [PATCH v3] i2c-mux-gpio: Check gpio_direction_output return value Message-ID: <20130307093553.4bc1595f@endymion.delvare> X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.7; x86_64-suse-linux-gnu) Mime-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org gpio_direction_output() may fail, check for that and deal with it appropriately. Also log an error message if gpio_request() fails. Signed-off-by: Jean Delvare Cc: Peter Korsgaard Cc: Wolfram Sang Acked-by: Peter Korsgaard --- Changes since v2: * Refreshed so that it applies on top of the most recent version of the driver. drivers/i2c/muxes/i2c-mux-gpio.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) --- linux-3.8.orig/drivers/i2c/muxes/i2c-mux-gpio.c 2013-03-07 09:06:31.431159507 +0100 +++ linux-3.8/drivers/i2c/muxes/i2c-mux-gpio.c 2013-03-07 09:07:02.739878467 +0100 @@ -201,10 +201,21 @@ static int i2c_mux_gpio_probe(struct pla for (i = 0; i < mux->data.n_gpios; i++) { ret = gpio_request(gpio_base + mux->data.gpios[i], "i2c-mux-gpio"); - if (ret) + if (ret) { + dev_err(&pdev->dev, "Failed to request GPIO %d\n", + mux->data.gpios[i]); goto err_request_gpio; - gpio_direction_output(gpio_base + mux->data.gpios[i], - initial_state & (1 << i)); + } + + ret = gpio_direction_output(gpio_base + mux->data.gpios[i], + initial_state & (1 << i)); + if (ret) { + dev_err(&pdev->dev, + "Failed to set direction of GPIO %d to output\n", + mux->data.gpios[i]); + i++; /* gpio_request above succeeded, so must free */ + goto err_request_gpio; + } } for (i = 0; i < mux->data.n_values; i++) {