Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5143271ybv; Mon, 17 Feb 2020 13:14:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwU9K20F/QqbMgnOOziVZ0Mf1PFilFMQ6ZyiOVz7gVpoKhglqapQrsko6XScLOlpiayoSp4 X-Received: by 2002:a05:6830:1d91:: with SMTP id y17mr12909482oti.276.1581974056798; Mon, 17 Feb 2020 13:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581974056; cv=none; d=google.com; s=arc-20160816; b=RKa2wu5Cy7q7wCtpXB3e5TJlGjwy03Q5sMK9fuGVqodwYYkdKz0WXAV4AYk+ovgEZE 4VIGkAiElTnLAxlxq501shxqzQCAqJgYnZTe8Ymzoho54SVPBZIS9K8K7wmM4gMyJj9y Yt98WWMuQg5EL0W1Nku+AYwlHq5QHccN5VaGjc9HDh9XbEnaXv4VN8Ggl0IxrA7YPEhJ QBRrD5gU2wz1vtLrxqTz6s/ar+mOdT6iEfUgXp+Qfz3yMkVanCmqGMEIWhUKEp1/bFno ElBRQp0ITLEWQ30FWynmVlcCKnuT3+EJpUP74uwZ+YtIeNyL4gsyGD6kKM+qhEpfBXK1 rFIQ== 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; bh=J0GeL7eRkd4dcjRk8OPC/BgFQWPRSyAiTzR79FFJ08w=; b=Hl9+skt0mnptCvQ8skDczjYrJfcT8l5vsEiqT+q1ToTe6tMnRD0HkICdQZHNAGpUBW NkotiGzB6infydgrdRPSCils0uoaBTeAmxCcZms6Ad1aALZ0miHI0GAAdd0iaB2sEX+V iEH0gDhRCmkN7S/VBzoyrQa4KLzhmwnB+17GIk9D3gqeSIAnTKLEErkfBfJ9yZSz6FNz lA1G0kM7TYQhidBQ2hgGIpAwMiV5HeauQknPADMaIMYqsjOoOiXb6L7HV/d9nzxi5jBl yZOqrH79oAA5iIAvlNwEljM329hQWVYzrBtmuAZ+8DfiVt8vqZtljVbHX7CjfeWZfnmb KzVg== ARC-Authentication-Results: i=1; mx.google.com; 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 o15si745142otp.314.2020.02.17.13.14.05; Mon, 17 Feb 2020 13:14:16 -0800 (PST) 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; 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 S1729851AbgBQVN3 (ORCPT + 99 others); Mon, 17 Feb 2020 16:13:29 -0500 Received: from mail-oi1-f195.google.com ([209.85.167.195]:37201 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729129AbgBQVN3 (ORCPT ); Mon, 17 Feb 2020 16:13:29 -0500 Received: by mail-oi1-f195.google.com with SMTP id q84so18039485oic.4; Mon, 17 Feb 2020 13:13:29 -0800 (PST) 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=J0GeL7eRkd4dcjRk8OPC/BgFQWPRSyAiTzR79FFJ08w=; b=edLGcrO/fE8YyjGi1wWA+YfvUjp3i1WeBe0mUWSbYdeauEn4xhr3JHhfdcc57NXm3O Shkyyzr7VY2wixBpbB+9XIBWeBDfgald+E1XbcA7O6BYVOhs+cH2HpB8cz3VOvTf066P vz3aCkKhHigRrUXxKMO+O0fCbf33uIDhqt5WW9T1FSm9FKq1gjUOITclBxul6y2fp+Wj fBEEETGz/frDd+ZuoKRGMXNXv5F5Tq+jSl/yZ5EvrTlxab3X7JVXxTRl9pQ426A+h5mP CLupQISvBw8/HWkWRIrZV0SPfIKmk7jiIwCdBSdniDlWW0niobNcRkbUhjmAOtuPzC8X L0dw== X-Gm-Message-State: APjAAAXCgouvJ79MnuaO7G3RJOwgwpCohcVcBwT1FptAl/XagiV10DCt z2usSwxcCtMZILg/0ZrcV0vgOidWukPLy/fPVgo= X-Received: by 2002:a54:4707:: with SMTP id k7mr562764oik.153.1581974008740; Mon, 17 Feb 2020 13:13:28 -0800 (PST) MIME-Version: 1.0 References: <20200217195435.9309-1-brgl@bgdev.pl> <20200217195435.9309-7-brgl@bgdev.pl> In-Reply-To: <20200217195435.9309-7-brgl@bgdev.pl> From: Geert Uytterhoeven Date: Mon, 17 Feb 2020 22:13:17 +0100 Message-ID: Subject: Re: [PATCH 6/6] nvmem: increase the reference count of a gpio passed over config To: Bartosz Golaszewski Cc: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Bartosz Golaszewski 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, Feb 17, 2020 at 8:56 PM Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > We can obtain the write-protect GPIO in nvmem_register() by requesting > it ourselves or by storing the gpio_desc passed in nvmem_config. In the > latter case we need to increase the reference count so that it gets > freed correctly. > > Signed-off-by: Bartosz Golaszewski Thanks for your patch! > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -349,11 +349,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > return ERR_PTR(rval); > } > > - if (config->wp_gpio) > + if (config->wp_gpio) { > nvmem->wp_gpio = config->wp_gpio; > - else > + gpiod_ref(config->wp_gpio); If gpiod_ref() would return the passed GPIO, or an error code, you could write nvmem->wp_gpio = gpiod_ref(config->wp_gpio); > + } else { > nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", > GPIOD_OUT_HIGH); > + } > if (IS_ERR(nvmem->wp_gpio)) > goto err_ida_remove; > Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds