Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7930643ybi; Tue, 9 Jul 2019 06:32:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiCLguh+rx7obMCXC6ozvP0J7jRNGRLtG6U8EL4xUH/CIO5ZSvkx5IwknBEPHIhUOZdrwm X-Received: by 2002:a17:902:7686:: with SMTP id m6mr8477064pll.239.1562679153918; Tue, 09 Jul 2019 06:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562679153; cv=none; d=google.com; s=arc-20160816; b=bcmAOxauemKy5zC9zoxFWncBmgWmVbM809KZ0QhfpvcgTAiL2mIzWo/5IEWbttzg5M gDU2OHHdO4vzWRoVGe0hbmdmOO94M86UUq3c/n4qIMHOOGaLuL+fJEVcFXWjClt0pfbl SwMhPqFYpPDJs+dwiifKCByc8Dww9nlqWrPh6F6ooxpyK5T0pSRWBCpAhIrmFYJ0yDda +LvWlFgaiG6T86MlAAYJ2xvQGP+5cmbfPD1O4829hk6cR9ZetAHjjkWPrUC3z15Mk15o sqCGQBavyYm5p527XQ4nkPYeMw4upr2C6z1wD1JWBWEmXqFdT8PqPFWESliMx4YGQdAK PfRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0aUhy01MvjYTIuBK0AjDqzuZqZYxgG2aAS7wxVUO+Ws=; b=v4+SHYvaQO+solKhZUcjvI8iM0LBPZc8Q8OsGnu84pmtqaGOntTr9ddp3VL83Wyboa 4cQoOKTu120RF05s3rK99ZzduugF60TwvBAdI5/fGWjaFAFeUblxKo3put8u8Z0cslTM CrRMslltLZxRgT8et1nZ/oaslLsPfctfHgLVXtHclWUEbkxWntyoP9yMg+/mfzwgma2M Uw6Ns5BPvNBQf7M+PtskyghzR9EQ/ngGmaZoudWjiUbLXK1I+WRpB4iHIbDJIJKfKnsJ BUd+GhFTKUoPJG38Kmn5M+UYyebb/WBxetVdBwW4Tz1DEsZ8iRJRMs0ifdaG5ICuLJMR me7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="JoYm0A/N"; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a15si20553053pgw.246.2019.07.09.06.32.17; Tue, 09 Jul 2019 06:32: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=@linaro.org header.s=google header.b="JoYm0A/N"; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726921AbfGINaf (ORCPT + 99 others); Tue, 9 Jul 2019 09:30:35 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:33958 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbfGINaf (ORCPT ); Tue, 9 Jul 2019 09:30:35 -0400 Received: by mail-lf1-f67.google.com with SMTP id b29so13468942lfq.1 for ; Tue, 09 Jul 2019 06:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0aUhy01MvjYTIuBK0AjDqzuZqZYxgG2aAS7wxVUO+Ws=; b=JoYm0A/NaqY/RJJ8uj0MbIJYXDsl5MJCKrhp/jp2LS2zO6pysb/Mb9/byTuAK7zFr9 X2eynOziS6C8SBX5vVQYnNem1NIY4zlXXQBpszyorhkYABCI/XqVSrJjXM8YSG0nmEUT lp7XJcaLcGLKkscah7/ZYbCliLd6Uvob9249QwNYQ59W6zGUYZ4Yxq3McUtmmD65917K oE3sM2HHEMG1nOfOscOoQ1BkhvdioxCnKxhcc/BsQxVyJFhJFgEaFwjX1gKpjnwzbq63 ZFyyHSsHwqJMfB7g0hhp36b5QJkY5Yj/jWTS+CWthz18hOQzNFfz41N49VXBuRvNt/wt 1tKQ== 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; bh=0aUhy01MvjYTIuBK0AjDqzuZqZYxgG2aAS7wxVUO+Ws=; b=XTbvZx81Yv3cYatj2PlxclzmKWkCR8KBMVDF3d9HEw66uGGqVUlO4lj/+1ClU/cQeT 4krM3r8M/R58ZBaCTfPXjAkeP515rFayPO3HYlrOIH5Bb2mjJRNcFmTyvI/ZlyZNO8lu wsXHshJhxoSVRKesgiH0cQDdwa9dSdURxSpjYnIHlfk/z99z09Vu+2TOTmiiVaBK7u1U wePgPZ6tjHYzB507SHV4K9uoJ3hyxJLoVYiZAMWQRFovfzD0cEt+M+lr+aQjEd0TBp7V tNoTlhsQfHzfyac8nFqZy/niHtLJIKrssL7KFIHe3nrmPzxNfoZ5CkIUG6HINHrqmJaD cE5Q== X-Gm-Message-State: APjAAAWkJnAR4oh0C2BTniEnMqtYd4DMBUgmcxfDzwhARM/4GQ90RQiq 3N2BSl5D5DWa5VcYsk9BbMU12Lw/k+IS9bEGkMhBBpFp X-Received: by 2002:a19:7616:: with SMTP id c22mr2897636lff.115.1562679033241; Tue, 09 Jul 2019 06:30:33 -0700 (PDT) MIME-Version: 1.0 References: <20190708082343.30726-1-brgl@bgdev.pl> In-Reply-To: <20190708082343.30726-1-brgl@bgdev.pl> From: Linus Walleij Date: Tue, 9 Jul 2019 15:30:22 +0200 Message-ID: Subject: Re: [PATCH] gpio: don't WARN() on NULL descs if gpiolib is disabled To: Bartosz Golaszewski Cc: "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Bartosz Golaszewski , "Claus H . Stovgaard" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). I was thinking something like this in the stubs: gpiod_get[_index]() { return POISON; } gpiod_get[_index]_optional() { return NULL; } 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.) 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