Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1682747pxj; Wed, 19 May 2021 11:22:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWXSdLp58X9nhBrTqZuoxoys6lFeaeXBNSQAiKjbdXveexRS/2KrZY4gwLcsqypvrYV8hS X-Received: by 2002:a17:906:2a08:: with SMTP id j8mr418623eje.483.1621448534470; Wed, 19 May 2021 11:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621448534; cv=none; d=google.com; s=arc-20160816; b=RiMAwLdtTvLzbUCqzaxSTVjAzh7Ox5K5Bk9LcaxdW2Cz+hof4FSkIWuymU486NDMhp 3xi6OPSWMxc2ZHvTHjdsNVuoayy6m4KA9lX6Jf3nNU/5LTODmoWM7jSjiu6orNkoMRFi bQYyVMeaQUiWUbRkPBSxkyKRihjWN8XZzVtb1zEAKYrPMqFPVTYIx7U0AVgAZYWrzJTG ikgkpnGwf42JBGpwQziCGXZ2mYt6JhqmBrLv0z/B7IP5z5AZ5SlldhZOomAzJdg9NvvM KgBCbCGlwBoR8t2oKGuSEuVI+Fcn1UMVn0nbf2IZsX2gaecC2SWiexVSptl1xYv3HeuN oFSg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=55uL4EwjB5KsqSrMi9DtnphLHt5YCKU1DOJ1EDArBPw=; b=SwqamiBFddvaFj9oOuJg/Jwl5XVcgP/5Bz+y5Q0PQu3xrVFOPsDKKe2mVaop+0xXdM G1xsRfl3mep+RNDS12zGUtQ92AKX9Sl0dKjGJM7QJE6Q5XTAl67L5tm1Cts6pjupDlZZ ihxjUhubKOSZTBn41JPXDycI+n4CrQb9dyydll9BNbydXLlsVtbWcrW63Kf6llDU5I/D 3gbNYeTPq70lzNOWx5AgEPw4zoCgx+qdrQCkcygy9krlyB3K1xQZnjCENqLbVpVxvvZE l9g6h+tcR/r1V1xIue/cTnhiYTYatDsmHYIiwxvp1HUgGM9N/7hXPyOsSsFvYfo9JOPu riAg== 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 x18si286885eji.715.2021.05.19.11.21.50; Wed, 19 May 2021 11:22:14 -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 S1350348AbhERPvW (ORCPT + 99 others); Tue, 18 May 2021 11:51:22 -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 S240361AbhERPvU (ORCPT ); Tue, 18 May 2021 11:51:20 -0400 IronPort-SDR: yGzgACAx1xS3+M6KIwUZWrUBoutGsHQY9BNdiqT+fXMM3hqt0VXswBFxQKjy7XW/0d3RXrJ/iu SQB9IO2JNcJQ== X-IronPort-AV: E=McAfee;i="6200,9189,9988"; a="197657334" X-IronPort-AV: E=Sophos;i="5.82,310,1613462400"; d="scan'208";a="197657334" 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:01 -0700 IronPort-SDR: fbd72Sc3wSKHE5OFTWe1UWU5h5glrGatWwUc3NlZjyK7XSwj3JnGnGvIpuhI6ovC74ZAkCtjcq nPOUQPjvd35w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,310,1613462400"; d="scan'208";a="411328261" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 18 May 2021 08:49:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1486750E; Tue, 18 May 2021 18:50:21 +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 Subject: [PATCH v1 2/2] gpiolib: Introduce gpiod_request_user() helper Date: Tue, 18 May 2021 18:50:13 +0300 Message-Id: <20210518155013.45622-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210518155013.45622-1-andriy.shevchenko@linux.intel.com> References: <20210518155013.45622-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The gpiod_request_user() is a special helper to avoid propagating stuff to user space that should not be propagated, e.g. internal error codes. For now, hide EPROBE_DEFER with ENODEV. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib-cdev.c | 21 ++++++--------------- drivers/gpio/gpiolib-sysfs.c | 7 ++----- drivers/gpio/gpiolib.h | 12 ++++++++++++ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 1d8f66880d63..8a934914f93a 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -330,12 +330,9 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) goto out_free_lh; } - ret = gpiod_request(desc, lh->label); - if (ret) { - if (ret == -EPROBE_DEFER) - ret = -ENODEV; + ret = gpiod_request_user(desc, lh->label); + if (ret) goto out_free_lh; - } lh->descs[i] = desc; linehandle_flags_to_desc_flags(handlereq.flags, &desc->flags); @@ -1381,12 +1378,9 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) goto out_free_linereq; } - ret = gpiod_request(desc, lr->label); - if (ret) { - if (ret == -EPROBE_DEFER) - ret = -ENODEV; + ret = gpiod_request_user(desc, lr->label); + if (ret) goto out_free_linereq; - } lr->lines[i].desc = desc; flags = gpio_v2_line_config_flags(lc, i); @@ -1770,12 +1764,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) } } - ret = gpiod_request(desc, le->label); - if (ret) { - if (ret == -EPROBE_DEFER) - ret = -ENODEV; + ret = gpiod_request_user(desc, le->label); + if (ret) goto out_free_le; - } le->desc = desc; le->eflags = eflags; diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index d836aba91d3c..22a9ad1a2978 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -473,12 +473,9 @@ static ssize_t export_store(struct class *class, * they may be undone on its behalf too. */ - status = gpiod_request(desc, "sysfs"); - if (status) { - if (status == -EPROBE_DEFER) - status = -ENODEV; + status = gpiod_request_user(desc, "sysfs"); + if (status) goto done; - } status = gpiod_set_transitory(desc, false); if (!status) { diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 69c96a4276de..7f760745c457 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -142,6 +142,18 @@ struct gpio_desc { int gpiod_request(struct gpio_desc *desc, const char *label); void gpiod_free(struct gpio_desc *desc); + +static inline int gpiod_request_user(struct gpio_desc *desc, const char *label) +{ + int ret; + + ret = gpiod_request(desc, label); + if (ret == -EPROBE_DEFER) + ret = -ENODEV; + + return ret; +} + int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, unsigned long lflags, enum gpiod_flags dflags); int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce); -- 2.30.2