Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7988072ybi; Tue, 9 Jul 2019 07:22:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5LSn3JKaMA8mEwjCrA+bqfrgncDjiyMKjvtiCyt7U8ggM01zYdE7F7zKXKZLL2HUa8dhg X-Received: by 2002:a63:550e:: with SMTP id j14mr21111572pgb.302.1562682136242; Tue, 09 Jul 2019 07:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562682136; cv=none; d=google.com; s=arc-20160816; b=xV4Dui6Jr7oftwQvEusE/sWzxrSJ0gbAzSirvwniuqixxV5IxW+54gJAY2C9gfpMfv iBs56Wwz/iqSmj7lF5iDiEfuN7Mu3tjSlilSaRgitR3LBDszWNASCLrqDIufx/nE5H73 5NaV5vP2VQUMcVMYaECsMfPANbBir9/MFzXtII4Dji/RIj3p0SCKU6OYd5ll68nSBMQd thbJ5NAAo/FXNpkF5qGN35m5wlPP6C84aPcPrYJ78vDNa5jypxeiTx3iPAgtl2rQh/vm aJQ2cOIMCmlHzd1MwBQOHdoMy8dOkc0ASGdi3sdc6l/f3XBurc64lDTCjRI2HAEuBk+a NH9w== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=XTag6E0HRY5pOM5AumSCXipohqiU4rMp+bu0B7wd10U=; b=C60V6zr289dS9pWKN/e2L2EmreusIpYV2bA2O3VdYaxlm0QJAj9Mz01cab6L6b5lP+ iw8yvV5P0KZu16Rfa6fd5BE7HuwAmp1IlYUOdYCrXvU9iIKDj5ZjnBfy479rJ5eREl2s WNY6f9IvvaQ3grq+YBWM+YUoHb35pCPoIAniLue6En2FTKVcWLmo17k58cmPxROug5ew 42QE152UK+gvnhO+Y94Hm1j7xRyN2EZVHqufyuQEo8/A5rQgBorUY1Axzv7rzhxf/nN8 DW/A67vyhmb64Z7ZKCRS3bdyPZhOVcprIMZT3EbSwtySdPRJ5plmmJXbDLgHe2gNPAIR olWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ph8QN36B; 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 w4si21482709plz.323.2019.07.09.07.22.00; Tue, 09 Jul 2019 07:22:16 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ph8QN36B; 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 S1726910AbfGIOUg (ORCPT + 99 others); Tue, 9 Jul 2019 10:20:36 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:42512 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbfGIOUg (ORCPT ); Tue, 9 Jul 2019 10:20:36 -0400 Received: by mail-io1-f66.google.com with SMTP id u19so43475615ior.9 for ; Tue, 09 Jul 2019 07:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=XTag6E0HRY5pOM5AumSCXipohqiU4rMp+bu0B7wd10U=; b=ph8QN36Brvz4GaO1lsbpAF+S34pEG3KOZn6OCqqyV1r0b+nSHJmHs7L5iApZcmsVSv ONf5pK1IYRZTeE67/2OjKhJHRZCppo+3gWxUhmDXn4+yhq1jps7zacdDz6o6mLUYFUHs CVlO6upXOLgmWTmrKu7/BwNkp9MuXH50C2ZvDFjidCtZMLY7PRpw1O61qy/t3FX+ehSd UPrjkFnjsJ1ogTjp/UKUxSg1d+xfwMMJIPB1w+b4TR0TkpSOXaopRjZqhSd6V07a9Nxo rkLl/VbzpFAsJT3woNWB36gFV7OlFYWRb3Mfody3109YK+h5qrJBFZ+2wqms8DRrsZ87 lPvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=XTag6E0HRY5pOM5AumSCXipohqiU4rMp+bu0B7wd10U=; b=Y8Yyl4QTo/W8OYKdP4WCJ/gW1y/3lM0ppMCw6gSMVY0ArdekzOxziG9vJcDtKYCp1t wavVCQDf1ZbB5KqJ71JsYKguIFJlMw6bv082bbfP4WaqanQF8zllp0z7tLliDZ+RJERs xD/LMm7aqK3chXjF0q+4iZy+hv3w2JxFvVIEqNyzo7B+P75bEaw7yIHO7Maec1cihSkK QRIOXIF8NcGI7/yq6JTnlCKExZ683izMBfMDzno4vdHm/dNQwZI/EI/+kcpDpwzrVAx6 DeXZa4UFNF0cmPJt/GS+TLt0hVLeCKiLdhoE7o86tMMzYqykGpw89ilIEA2rzPH+sic7 CHOQ== X-Gm-Message-State: APjAAAVplk7ThwNm/lTjMfGYvEdO0XuVDFHi8XgemrH6gjzoBLOjMnHn 0O+Y8HYB8EuYwDCgYzDGytrUGUDZiOTGsqWPMEARkg== X-Received: by 2002:a5e:8b43:: with SMTP id z3mr516301iom.287.1562682035066; Tue, 09 Jul 2019 07:20:35 -0700 (PDT) MIME-Version: 1.0 References: <20190708082343.30726-1-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Tue, 9 Jul 2019 16:20:24 +0200 Message-ID: Subject: Re: [PATCH] gpio: don't WARN() on NULL descs if gpiolib is disabled To: Linus Walleij Cc: "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Bartosz Golaszewski , "Claus H . Stovgaard" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org wt., 9 lip 2019 o 15:30 Linus Walleij napisa=C5= =82(a): > > Hi Bartosz, > > On Mon, Jul 8, 2019 at 10:25 AM Bartosz Golaszewski wrote= : > > > From: Bartosz Golaszewski > > > > If gpiolib is disabled, we use the inline stubs from gpio/consumer.h > > instead of regular definitions of GPIO API. The stubs for 'optional' > > variants of gpiod_get routines return NULL in this case as if the > > relevant GPIO wasn't found. This is correct so far. > > > > Calling other (non-gpio_get) stubs from this header triggers a warning > > because the GPIO descriptor couldn't have been requested. The warning > > however is unconditional (WARN_ON(1)) and is emitted even if the passed > > descriptor pointer is NULL. > > > > We don't want to force the users of 'optional' gpio_get to check the > > returned pointer before calling e.g. gpiod_set_value() so let's only > > WARN on non-NULL descriptors. > > > > Reported-by: Claus H. Stovgaard > > Signed-off-by: Bartosz Golaszewski > > I remember I had this discussion in the past, and I made a large > refactoring to make it possible for drivers that need gpiod_* > calls to simply do: > > select GPIOLIB > > in Kconfig. > > This should solve also this problem I think. > > However I do realize that there may be situations where people > simply want to make GPIO support entirely optional without > having to e.g. create custom stubs and encapsulate things > inside if IS_ENABLED(CONFIG_GPIOLIB). > In this case the board doesn't provide any GPIO controller at all so there's simply no need to select GPIOLIB - it would only add bloat. > I was thinking something like this in the stubs: > > gpiod_get[_index]() { > return POISON; > } > > gpiod_get[_index]_optional() { > return NULL; > } This is already being done. > > This way all gpiod_get() and optional calls are properly > handled and the semantic that only _optional calls > can return NULL is preserved. (Your patch would > violate this.) > Maybe I'm missing something, but I don't quite see how my patch violates this behavior. :( > Then other stubs can do: > > gpiod_set_value() { > WARN_ON(desc); > } > > As in your patch, and all will be smooth provided the > _optional calls have been used to obtain the desc. > > Yours, > Linus Walleij Bart