Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1303827pxu; Sat, 5 Dec 2020 10:48:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZ+qPkOY1ijXYJsnBsL2gKchSgPWRed18grOZNwsq3tiNC4jiPZQ5aPy6WMd0dnVysxO/S X-Received: by 2002:a17:906:304c:: with SMTP id d12mr12805082ejd.84.1607194134104; Sat, 05 Dec 2020 10:48:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607194134; cv=none; d=google.com; s=arc-20160816; b=OdhifFsmgxsL393Zrw2At/JadmA+rJwFDFeDpA4wbxXgi8yFW3qd5xrTIL19e1bL0v /p4R+jocS7KpLbUkFcFHFv1uj33tNKCCHn25xQdDrcHo2UAIqzmx9G3Ki+rinwdTwur1 UU37ftuFN2m2rbrvm3JYlruu9qbUgnK65OmXT8DcqSfRC5LDypHDNVSjx8TwIa7BCLkT WHGPB2elD2MGCFpInW5qYnLJi10i6Jmq0s1WKkhNtOOPByRirR8Fx5inWzp7QIcmzeTU eWq8KD8pKYdE/cXRKo4FQU/2kvRgX+i6K63AMq6YXhEixw+G0EC+lNG63fqNzefoYF6X kaww== 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:subject:cc:to:from:date; bh=YDu1QeK6MK9Cuo5KqgBLJLgCIN9pRJXb3+sWcgg68yg=; b=xoeFwr4BWL8ssAYprGRgQGTyLE0YsJzC5PVYY7iya29WGgfMOsspVURnKXOtQWmtGP Zl9hxxFcovECxlh938GkpcS2Wmzl3/MTX33DgptMGrJocKnHJwfCIgEb2CzWHcrtZDyQ 5QQoEI7v2TdEaN/yFNEQbQzh5jvJB89o8b+QTz8jszKE2GhSAbrzizyoHeeadkurykVT SW/TndR1LBBtcXl0oJEj6kfbJAfh+avlFo+oMX8GfIcwym6A702sI63uR0I40Ax+kuGJ lCfdbbrd+Qn6zxU+SIiwsOZEM1WeYCjSyUDAFrcNpWk1JoFwNx4jJuxqKdf91bGdJw57 5YiQ== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si3715597ejn.17.2020.12.05.10.48.31; Sat, 05 Dec 2020 10:48:54 -0800 (PST) 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728221AbgLESpJ (ORCPT + 99 others); Sat, 5 Dec 2020 13:45:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:49666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbgLEQtb (ORCPT ); Sat, 5 Dec 2020 11:49:31 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5649523341; Sat, 5 Dec 2020 16:36:21 +0000 (UTC) Date: Sat, 5 Dec 2020 16:36:18 +0000 From: Jonathan Cameron To: Alexandru Ardelean Cc: , Subject: Re: [PATCH 1/3] iio: dummy: convert all simple allocation devm_ variants Message-ID: <20201205163618.3b26334f@archlinux> In-Reply-To: <20201203095005.72252-1-alexandru.ardelean@analog.com> References: <20201203095005.72252-1-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 3 Dec 2020 11:50:03 +0200 Alexandru Ardelean wrote: > Since a main requirement for an IIO device is to have a parent device > object, it makes sense to attach more of the IIO device's objects to the > lifetime of the parent object, to clean up the code. > The idea is to also provide a base example that is more up-to-date with > what's going on lately with most IIO drivers. To some degree maybe, it's also very very handy for testing odd corner cases with. I'd definitely not recommend it as a reference driver because it inherently has some odd corners because we need to fake various things that don't exist without hardware. > > This change tackles the simple allocations, to convert them to > device-managed calls, and tie them to the parent device. I'm confused or maybe I missrecall how this works. IIRC there isn't a parent device... Maybe we could create one via a bit of smoke and magic. > > Signed-off-by: Alexandru Ardelean > --- > drivers/iio/dummy/iio_simple_dummy.c | 29 ++++++++-------------------- > 1 file changed, 8 insertions(+), 21 deletions(-) > > diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c > index c0b7ef900735..2a2e62f780a1 100644 > --- a/drivers/iio/dummy/iio_simple_dummy.c > +++ b/drivers/iio/dummy/iio_simple_dummy.c > @@ -574,11 +574,9 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) > * parent = &client->dev; > */ > > - swd = kzalloc(sizeof(*swd), GFP_KERNEL); > - if (!swd) { > - ret = -ENOMEM; > - goto error_kzalloc; > - } > + swd = devm_kzalloc(parent, sizeof(*swd), GFP_KERNEL); > + if (!swd) > + return ERR_PTR(-ENOMEM); > /* > * Allocate an IIO device. > * > @@ -587,11 +585,9 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) > * It also has a region (accessed by iio_priv() > * for chip specific state information. > */ > - indio_dev = iio_device_alloc(parent, sizeof(*st)); > - if (!indio_dev) { > - ret = -ENOMEM; > - goto error_ret; > - } > + indio_dev = devm_iio_device_alloc(parent, sizeof(*st)); > + if (!indio_dev) > + return ERR_PTR(-ENOMEM); > > st = iio_priv(indio_dev); > mutex_init(&st->lock); > @@ -615,7 +611,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) > * indio_dev->name = id->name; > * indio_dev->name = spi_get_device_id(spi)->name; > */ > - indio_dev->name = kstrdup(name, GFP_KERNEL); > + indio_dev->name = devm_kstrdup(parent, name, GFP_KERNEL); > > /* Provide description of available channels */ > indio_dev->channels = iio_dummy_channels; > @@ -632,7 +628,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) > > ret = iio_simple_dummy_events_register(indio_dev); > if (ret < 0) > - goto error_free_device; > + return ERR_PTR(ret); > > ret = iio_simple_dummy_configure_buffer(indio_dev); > if (ret < 0) > @@ -649,11 +645,6 @@ static struct iio_sw_device *iio_dummy_probe(const char *name) > iio_simple_dummy_unconfigure_buffer(indio_dev); > error_unregister_events: > iio_simple_dummy_events_unregister(indio_dev); > -error_free_device: > - iio_device_free(indio_dev); > -error_ret: > - kfree(swd); > -error_kzalloc: > return ERR_PTR(ret); > } > > @@ -683,10 +674,6 @@ static int iio_dummy_remove(struct iio_sw_device *swd) > > iio_simple_dummy_events_unregister(indio_dev); > > - /* Free all structures */ > - kfree(indio_dev->name); > - iio_device_free(indio_dev); > - > return 0; > } >