Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1263926imu; Wed, 16 Jan 2019 15:59:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN7+uUHLAwf/cqXay6RYOCc87jSFIPWCNmnwHW3mJ90apCSSlNpzd1dr4dJvM5NXOqffsb0v X-Received: by 2002:a17:902:8641:: with SMTP id y1mr12585440plt.159.1547683194360; Wed, 16 Jan 2019 15:59:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547683194; cv=none; d=google.com; s=arc-20160816; b=v0sAc3iDrcSzKNvg+HX0vu6GLCbGYW5vqWhgRCNWaHP8bCyVRvsoEfGCPS3smWm7ZB gWmUAVUSdMEkmb2F14ELluAvEy7iChKlqeJfSKsLETtQx4K4DsCuDV+q4OZpAgKbwUZt AA+NT0UWJJoOA1vTMSYB6lQtlBhVjKHlRFnwNHOFDetyQgoJ9w4NPC4EYs4oIcdjnhrc zGCe5klvyzkFNJgbKfct93SwiW/6yAEYsDo35wBj7xwPHcqJ/yDL1+C/U7GwMlOucfZ4 7u1U6cZpwZeemRJb+tsytBjas8+JkOktVEKEE+Hg+wb1FUqq+NlGdCY0e3o1qRCSUjBZ d5fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date; bh=9pBjQvSVjZbuaee//S1h12VQBjkhmCkC3C/lAAyJcwo=; b=lZYK15WiGGS/u0jpc6skRJnZwofVXK6gFnFKAIf2DkmtXug5dKcOy5+0S421xpehKD ba9Zn2zj4jZ0voUxeTKOfDyHAiuObwGeHiRlICLEr9G8HDc8UwJaj+v36/0UZNOkBKxl F4RjcsTpJtsdZ3K8SarEnXY8zOKu2MiAqoJGGQoEz4oeogNLbl0Js42gzdKsWWJfIW5e gNwxxV8qDKg4Yo9MkHmEgNwLheJkXnGiCyr+NmrRmTcYt4XGrx7b4SChyqFV9Unwl9xv LbvlCJwu8fqDNDDNZB9BbBh/QtNJhy1FmlG2VKITxFX9rjBfIpjKc5kNmY6USWna4cPU CPbg== 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 n13si6834568pgp.307.2019.01.16.15.59.36; Wed, 16 Jan 2019 15:59:54 -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 S1728835AbfAPS1I (ORCPT + 99 others); Wed, 16 Jan 2019 13:27:08 -0500 Received: from smtp1-g21.free.fr ([212.27.42.1]:4805 "EHLO smtp1-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728195AbfAPS1I (ORCPT ); Wed, 16 Jan 2019 13:27:08 -0500 Received: from tack (unknown [IPv6:2a02:8108:4840:8f74:a08c:f56:b2dd:7ae0]) (Authenticated sender: albeu) by smtp1-g21.free.fr (Postfix) with ESMTPSA id 7A011B0058E; Wed, 16 Jan 2019 19:27:00 +0100 (CET) Date: Wed, 16 Jan 2019 19:26:58 +0100 From: Alban To: Srinivas Kandagatla Cc: Aban Bedel , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/8] nvmem: Add nvmem_cell_get_optional and devm_nvmem_cell_get_optional Message-ID: <20190116192658.7df211e8@tack> In-Reply-To: References: <20190106192820.12558-1-albeu@free.fr> <20190106192820.12558-4-albeu@free.fr> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/BnuoXlM.vOTuMS9AUjPKwOp"; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Sig_/BnuoXlM.vOTuMS9AUjPKwOp Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Tue, 15 Jan 2019 12:40:53 +0000 Srinivas Kandagatla wrote: > On 06/01/2019 19:28, Alban Bedel wrote: > > Add helper functions to make the driver code simpler when a cell is > > optional. Using these functions just return NULL when the cell doesn't > > exists or if nvmem is disabled. > >=20 > > Signed-off-by: Alban Bedel > > --- > > drivers/nvmem/core.c | 48 ++++++++++++++++++++++++++++++++++ > > include/linux/nvmem-consumer.h | 16 ++++++++++++ > > 2 files changed, 64 insertions(+) > >=20 > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > > index f8c43da6f2ca..8e1b52559467 100644 > > --- a/drivers/nvmem/core.c > > +++ b/drivers/nvmem/core.c > > @@ -1083,6 +1083,30 @@ struct nvmem_cell *nvmem_cell_get(struct device = *dev, const char *id) > > } > > EXPORT_SYMBOL_GPL(nvmem_cell_get); > > =20 > > +/** > > + * nvmem_cell_get_optional() - Get an optional nvmem cell of device fr= om > > + * a given id. > > + * > > + * @dev: Device that requests the nvmem cell. > > + * @cell_id: nvmem cell name to get. > > + * > > + * Return: Will be NULL if no cell with the given name is defined, > > + * an ERR_PTR() on error or a valid pointer to a struct nvmem_cell. > > + * The nvmem_cell will be freed by the nvmem_cell_put(). > > + */ > > +struct nvmem_cell *nvmem_cell_get_optional(struct device *dev, > > + const char *cell_id) > > +{ > > + struct nvmem_cell *cell; > > + > > + cell =3D nvmem_cell_get(dev, cell_id); > > + if (IS_ERR(cell) && PTR_ERR(cell) =3D=3D -ENOENT) > > + return NULL; =20 >=20 > What is the real use-case here, it does not make sense to me to add this= =20 > additional call just to return NULL when cell is not found! It also return NULL when nvmem is not compiled in. I quiet like such convenience functions as they make the driver code much simpler and the intent explicit. It replace: data->cell =3D devm_nvmem_cell_get(dev, "my-cell"); if (IS_ERR(data->cell) { if (PTR_ERR(data->cell) =3D=3D -ENOENT || PTR_ERR(data->cell) =3D=3D -EOPNOTSUPP) data->cell =3D NULL; else return PTR_ERR(data->cell); } with: data->cell =3D dev_nvmem_cell_get_optional(dev, "my-cell"); if (IS_ERR(cell)) return PTR_ERR(data->cell); It's your call if you find that useful or not. Alban --Sig_/BnuoXlM.vOTuMS9AUjPKwOp Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE0W61GceYqNjiMSkodJSaS524LbwFAlw/d3IACgkQdJSaS524 Lby4OhAAk2EKLbGZ6IvsG+YelauFhWszQp2IRXo9Ff4Vwy5SyOcPw/yLuhvlXIRX 4GTn7p6E/zNceO2bAnFcM4z4pp/qZqRMBSX4uQnQhDhs+oTRfwGWd4pZmGvJvjg+ pGBGJn1aHBXzFM7cKB7dD54AiM6diesX946xAV55wr0FHQdZtSasntKeg6DnJn+R vlQf8vy2YzN6HDVDB7NVvqD/x6LYGXDcfWUtZ3f2q79Qh0sM6VKsp94AKMhjWo1/ xeIsTX489ZZJOho62nszYDX7aFN5vPvIRKW/2AR4OnjUUofpmFUJvvCBWZWtbZtY zJ6OsSHSCum/wvTmQgAnydICGEQu0O5bR/MduOaObamZ9prhHnaXHf4B3OPDOjWg TF78q4gW+AJXvO24Sbzw6Iib+J2NpQ9+r7kHXCkhY4XnyY12rqavm5gZaICDl9Dx qRNHbacs8lzMx4vVNST8zFZ8/1hGP4VQrLyq4Fh4dVTa8XAV6ax30eje1DzU/aDs SpQJrMf2WJePsOC3MJ3pHEjjHl7AHma9A8VEWKSHOqIU2YSpL/5KOVAdhAlIPXfX T7ddt1AfpnnlBsgYS8Fu4vItBqdm//hJcC5j1iak2yoi3m2+/Jq1RyPmXQn/O9r9 XE/04nOvE2+uVR9NWrob8yc+F9/Kz9lmzgA6bQVdMuB8g8alA1w= =p3qI -----END PGP SIGNATURE----- --Sig_/BnuoXlM.vOTuMS9AUjPKwOp--