Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5225539ybl; Tue, 27 Aug 2019 01:06:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmUbCIhMWSu0JxNSSVEwclDP8rrlQomsNn3froxNEGWHuYo7WCJWsPvj084Rsz3QwkvFrJ X-Received: by 2002:a63:e901:: with SMTP id i1mr19740220pgh.451.1566893185664; Tue, 27 Aug 2019 01:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893185; cv=none; d=google.com; s=arc-20160816; b=DQB02+XtEz2HYY/98VJbW+3GtFtGVLtT+KUHpfnmUJh5Bnug+3AfjeiC0NKqs/C+pt hhfiZ/FElAOAlFaxfmPGUzLivs6bA6tAPbOoS2InE5J/SJGoxTzckC33orVxwEYC60qG la32vIMMidJlxSLdyTToOArvcn6kS5qLQ3cl0p3bY6A1OSWIwSTCTSKSdHhaXllg/7X5 x4NkG40LMWz/q4hNs7oA21vCcUt3+rBzV1oLGLDRd5VdrQRvxaw0psn/jPRzMAfHcWR5 VkvTJRnkXZTyUf3CoVTGTSagmVQ0Clb9z2Cz9YmPmbmjhTPFXlH/xMQarajYl5ourXLb CHeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=++iQ1cEFCxMJh8MprDfMTa7a+HgCydveFVnXnzDhEaM=; b=ff8T26pOagMV1lxRIytCUB2LKBZUyQ01sPb0cXoSaJXplaSFhTJcpqyTYWFfOpqaJT AsV/8Ae0bu6PEzgYspoaT5zmXLI6zaiwipRtK0Vea2L5yDkgGFca7pWctVFOg0vParhO hxRbP7mE+DyHj4ez/WdxYjshSh/qu18EKDQWxFPrTOINjQk5/4A7rVibOxSQ5JjtXupT gdRr2amxT8GLLl0LbiBc8U8FeVEwAXaSnb70qz7hojlH/NbWUiLTDgZ7vSshQA4JIsBH xVOn0x0xjQK9OXAjjvv7u8hxBaL30UzwKoCv6cmuluRmUcwLsFt7sUlzO0kVMgH0B6jF WKJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NlCqGaML; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si11502287pgj.171.2019.08.27.01.06.10; Tue, 27 Aug 2019 01:06:25 -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=@kernel.org header.s=default header.b=NlCqGaML; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732700AbfH0IFJ (ORCPT + 99 others); Tue, 27 Aug 2019 04:05:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:34680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731504AbfH0IFD (ORCPT ); Tue, 27 Aug 2019 04:05:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A755E206BF; Tue, 27 Aug 2019 08:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893103; bh=6/LSERst0QCgem5FWEXCFqLvc3K/txrFkPNguJrGEq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NlCqGaMLUJMVeRYbbi/jKoffDLj0c6UVUAVOoAyFCp3Q3vjIn+CbY61FXO14/Xi/J QidZ8fB9BS4uBn39xI56gFCRw99Ge11uYXY+1HRrIfc84eD0tKgAzMCqEq2lAZJx+9 kcpm7g5HfmfOgLIFAw2Gy9gcOvIZXB3YlauW/JVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bartosz Golaszewski , Linus Walleij Subject: [PATCH 5.2 122/162] gpiolib: never report open-drain/source lines as input to user-space Date: Tue, 27 Aug 2019 09:50:50 +0200 Message-Id: <20190827072742.714900074@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski commit 2c60e6b5c9241b24b8b523fefd3e44fb85622cda upstream. If the driver doesn't support open-drain/source config options, we emulate this behavior when setting the direction by calling gpiod_direction_input() if the default value is 0 (open-source) or 1 (open-drain), thus not actively driving the line in those cases. This however clears the FLAG_IS_OUT bit for the GPIO line descriptor and makes the LINEINFO ioctl() incorrectly report this line's mode as 'input' to user-space. This commit modifies the ioctl() to always set the GPIOLINE_FLAG_IS_OUT bit in the lineinfo structure's flags field. Since it's impossible to use the input mode and open-drain/source options at the same time, we can be sure the reported information will be correct. Fixes: 521a2ad6f862 ("gpio: add userspace ABI for GPIO line information") Cc: stable Signed-off-by: Bartosz Golaszewski Link: https://lore.kernel.org/r/20190806114151.17652-1-brgl@bgdev.pl Signed-off-by: Linus Walleij Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1091,9 +1091,11 @@ static long gpio_ioctl(struct file *filp if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) lineinfo.flags |= GPIOLINE_FLAG_ACTIVE_LOW; if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) - lineinfo.flags |= GPIOLINE_FLAG_OPEN_DRAIN; + lineinfo.flags |= (GPIOLINE_FLAG_OPEN_DRAIN | + GPIOLINE_FLAG_IS_OUT); if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) - lineinfo.flags |= GPIOLINE_FLAG_OPEN_SOURCE; + lineinfo.flags |= (GPIOLINE_FLAG_OPEN_SOURCE | + GPIOLINE_FLAG_IS_OUT); if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) return -EFAULT;