Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1682279pxj; Wed, 19 May 2021 11:21:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8aDw+GbodWQjlk4bkDGgiYJ7eq782PwFl13IAZICi6RytePHZRKGdzGCGSJg8OFZOpISc X-Received: by 2002:a5d:9959:: with SMTP id v25mr850317ios.85.1621448489783; Wed, 19 May 2021 11:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621448489; cv=none; d=google.com; s=arc-20160816; b=MkChKVdUHcB9qx8GmTshu5n73ivRpua78rnJtMCJ4WCOU514D1dm7JjfAfcGbXqJhv 9RzOoC1hungFRT/MOIDfkCy1qgQUFtrj74Hya0vWRy8V+szqlUCldxC9/OHsPvVA96QM aetkB3Hc/CCkSf1o7EYh7Q/9TdBmSQ5OVXMgfDBF1AIfEJc8PC/seM2DH0GFLo0U1ZSS rYETmsPklexfotStTiELrta8fqrI7wdzYId6RTbzOfyDAXc3xjy1h3YkIqMhc69PP9GX 41qn1rrX7BDCoQ5y9StrPaWOSUiUKjy9fqWlxhoDTkDmekQrLtJmxoA5ub4UfmL9PqqZ r9cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=jiCdKGFA6aaWV6Ss6fsvDZhka+qMrfji3wqQpDeU0Q4=; b=V+ZK7UW0/wwMsNvnMl4h9sE+lq2h8IErW4R7Z6dUY+bTdVJhbRjicbrBijl1aKnH/1 x/pQWMn1nrpBDdXUm9TXOhfRfzZ10wfauutFJWzPRbC/cWDkKkDHYX5a5IHH1USyAmhQ 1JpHHgwoSume6kTpJ82FmACWiZpjqlwduM2tIiWgAsXgpp5nLctsqczK5YTRAFw/Bbhr tKg8MJ96rkskCXuPBd/PkcW/qopJnFuLuWVW3ABklqicTb6BkbRtvKF8s4gj6F+VqO3b U6Gnn5bHdAlNn3hffkgH1AWnc7iVx6IB/bccbkrd9OFgDVKAV6i6H8S1EtdKAHuC2baw jbPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 7si332652ilz.34.2021.05.19.11.21.16; Wed, 19 May 2021 11:21:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344784AbhERPvU (ORCPT + 99 others); Tue, 18 May 2021 11:51:20 -0400 Received: from mga11.intel.com ([192.55.52.93]:45895 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244533AbhERPvT (ORCPT ); Tue, 18 May 2021 11:51:19 -0400 IronPort-SDR: /pYI1ZoLG7TMiPJEk7OoexsZC0C/R4B3PGmXwKj4rIOnD2D5H15gAd+DGbV8cE/JwMUK0eSaj1 pAXRelGtjLcA== X-IronPort-AV: E=McAfee;i="6200,9189,9988"; a="197657331" X-IronPort-AV: E=Sophos;i="5.82,310,1613462400"; d="scan'208";a="197657331" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2021 08:50:00 -0700 IronPort-SDR: J6YrVZQkYKx+An4K5vDSlHfYFMiKMlVYAMS24LqhM5IAE+L/X8KC0+BQgEDuPhPz+Etyswjc4I 8nMojLixL2/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,310,1613462400"; d="scan'208";a="411328265" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 18 May 2021 08:49:58 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id B15BF348; Tue, 18 May 2021 18:50:19 +0300 (EEST) From: Andy Shevchenko To: Kent Gibson , Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Suresh Balakrishnan Subject: [PATCH v1 1/2] gpiolib: Never return internal error codes to user space Date: Tue, 18 May 2021 18:50:12 +0300 Message-Id: <20210518155013.45622-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently it's possible that character device interface may return the error codes which are not supposed to be seen by user space. In this case it's EPROBE_DEFER. Wrap it to return -ENODEV instead as sysfs does. Fixes: d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines") Fixes: 61f922db7221 ("gpio: userspace ABI for reading GPIO line events") Fixes: 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL") Reported-by: Suresh Balakrishnan Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib-cdev.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 1631727bf0da..1d8f66880d63 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -331,8 +331,11 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) } ret = gpiod_request(desc, lh->label); - if (ret) + if (ret) { + if (ret == -EPROBE_DEFER) + ret = -ENODEV; goto out_free_lh; + } lh->descs[i] = desc; linehandle_flags_to_desc_flags(handlereq.flags, &desc->flags); @@ -1379,8 +1382,11 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) } ret = gpiod_request(desc, lr->label); - if (ret) + if (ret) { + if (ret == -EPROBE_DEFER) + ret = -ENODEV; goto out_free_linereq; + } lr->lines[i].desc = desc; flags = gpio_v2_line_config_flags(lc, i); @@ -1765,8 +1771,11 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) } ret = gpiod_request(desc, le->label); - if (ret) + if (ret) { + if (ret == -EPROBE_DEFER) + ret = -ENODEV; goto out_free_le; + } le->desc = desc; le->eflags = eflags; -- 2.30.2