Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp483513imm; Fri, 21 Sep 2018 03:36:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaAnmgjgEajz2AL+yI/tkQOjvYVpmYfvjlk1H+eMTTPlBGVnaXiO+F44Be4zCCODK2owDMS X-Received: by 2002:a62:20f:: with SMTP id 15-v6mr46228980pfc.100.1537526193689; Fri, 21 Sep 2018 03:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537526193; cv=none; d=google.com; s=arc-20160816; b=ysSy9y+4xI6D9c0J+YTI7xRU6aydark0HEB5dX8YVlBIlffJccXnJlqkdCoQpCdNx6 SC74xUqntBJuvNySW2GkBG2yAEr+x36jGRGkRDwI3pAXA3JkqFke0SnZ56fObpikrQjS eIHBwNhGbptwqxGvJfs3j3IXr10FusNgITaNria3AhyFkdz3dmotBEBSuXzkOaM7ncd1 supg3uGyPXRoTD5nZ1wjgNImdoakjPMxYrH+mvW3pa+6iPvPwRmrFwVRsi6QJnHpvgtT WgKXe1iboCj44NeRGwCY7SXBIk8FdN4N4rvt3z4bsOTs7C4U4ids6p5mLH2GsOM9pq7Q h6zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6fncp2wBKiaAhFqes5VbfWoYDTuWvL2B06DeOxEt5SM=; b=KmReweXTJF5PiSzBOISZ/jqiBUCVVxhYn3WPJqABuiP/LjLk3de1KieDruUFuWp9on 6ch3HrjCwH8xdQktaZgVC0enJAX21NZJ2rY/tJw4lC+bisZ7ecCXvCMtvDz0n2yaBlQ7 Oc0/t9Td6cE7KS0nUT+bVLbrQw500k4gqbJrlGPqpvofa4xMYCZEMh1eHsnk/iaqoF3G PyP/Owpm7e6X/RIj3vILT+eng/J2lIy1u6TzGpsh/yOvskbE75C1FbogFr936/pUJlar njZ1gjTtSJJp5vCYTzvUNJ79LQErDzdErd6iYzrJPRsFq3xU/v11wwLUxhvmgTEr9Son 0qjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SdC4Sc3c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64-v6si27232305pli.56.2018.09.21.03.36.18; Fri, 21 Sep 2018 03:36:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SdC4Sc3c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389776AbeIUQY0 (ORCPT + 99 others); Fri, 21 Sep 2018 12:24:26 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:46190 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727554AbeIUQY0 (ORCPT ); Fri, 21 Sep 2018 12:24:26 -0400 Received: by mail-ed1-f68.google.com with SMTP id k14-v6so10302012edr.13; Fri, 21 Sep 2018 03:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6fncp2wBKiaAhFqes5VbfWoYDTuWvL2B06DeOxEt5SM=; b=SdC4Sc3c1H+O8OJTrSmV9MNm9SmoO/lrebyfMRX9FWmHF8czXdSYPIQZPJxb4SldoD CL1Wo7PGKxAzY+4RcBxmvfMXaov3brxpQ8ht+aQtzSrzfm1ANllzJuhV3HLXDPZEbegq 78QA/beyhhcYkbI0BL4IGU0pY/IWl3YW8s58aLDHyR7IiSPVNsCseAbJJJ8tdiW2we1c FmUPU4hVlquDneN3wfopugIW0iCz7T8WVoAwJdWfaSiPrw0cDTlJK1RwLVdGXIxiqGzt PQk91lBjqnWLybGEJCkGYtibZnUgrBwtPNnUf/HPvRKugiIjDtsetmuBtbs41i9A1ZuC scRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6fncp2wBKiaAhFqes5VbfWoYDTuWvL2B06DeOxEt5SM=; b=IfJ/m2y6/6DpgOXfJbJdeyfjFZWifx8l62WEWs8n17piIWMsXwewXYw/RMzcOhl2V1 iyTDLkDXBsWbWX97pUDf6m2k1+xqGxU8uZzHsyf/UArddvJrkRJgr3V3/NONYk4h6V3J 1iiI+Q97I38To9sZbLA7S0og0nFOv+HUxYTLaSRmqdQDRFJyROIs0g259aR802iFSFGt DBgDblsjyz2UsG9buPq5D0GLTzmty/WnaRVbqU+4B3UZWeqNf9s86J9zPWWcEGcqCLHZ uEJnKFe4Ft4JOQE3SPLavu2iG84H083XkviqPKLQX+4Ji2AMJsEKG8lA1mT3+t/Y5UHU 8gVw== X-Gm-Message-State: APzg51C6uZ9PDeBYIOCLf8OgFh+zKQKtHoZb8FAkyrH0xF1JoYze0ubv PmTDfIN1FqyV1C+uyhFvwA0= X-Received: by 2002:a50:8345:: with SMTP id 63-v6mr10583836edh.5.1537526168721; Fri, 21 Sep 2018 03:36:08 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id k28-v6sm1900871ede.11.2018.09.21.03.36.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 03:36:07 -0700 (PDT) From: Ricardo Ribalda Delgado To: Linus Walleij , Timur Tabi , swboyd@chromium.org, linux-gpio@vger.kernel.org, LKML Cc: Ricardo Ribalda Delgado Subject: [PATCH v2] gpiolib: Show correct direction from the beginning Date: Fri, 21 Sep 2018 12:36:04 +0200 Message-Id: <20180921103604.13361-2-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180921103604.13361-1-ricardo.ribalda@gmail.com> References: <20180921103604.13361-1-ricardo.ribalda@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current code assumes that the direction is input if direction_input function is set. This might not be the case on GPIOs with programmable direction. Signed-off-by: Ricardo Ribalda Delgado --- drivers/gpio/gpiolib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4b45de883ada..00c17f64d9ff 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1352,7 +1352,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, * it does, and in case chip->get_direction is not set, we may * expose the wrong direction in sysfs. */ - desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; + if (chip->get_direction && gpiochip_line_is_valid(chip, i)) + desc->flags = !chip->get_direction(chip, i) ? + (1 << FLAG_IS_OUT) : 0; + else + desc->flags = !chip->direction_input ? + (1 << FLAG_IS_OUT) : 0; } #ifdef CONFIG_PINCTRL -- 2.18.0