Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3729744ybt; Sun, 5 Jul 2020 05:06:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/PftT8XgH8KQJbiwpcVehte3ePRzsrzTIG+L39lC3Nk3gDfVSDniunpcg3WOvZE4pRa/h X-Received: by 2002:a17:906:4a44:: with SMTP id a4mr31740874ejv.486.1593950805125; Sun, 05 Jul 2020 05:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593950805; cv=none; d=google.com; s=arc-20160816; b=q36I8w7feEE4gqbihJt0NJh6T8W/w+xZncrSriNnSQosMuxfDUpx2FNIFMCUF1tPCd R0fZhit2roXmQRoCd46QflXSIpQ51nI+lIieOHiskqKiZ672PEBoblzvAeOqBHKBsf9z 8Sh1vTCyvmLj5vcmkAXuz7ckzdnhxZ/aT6KqOFGZRi0lbanjpGjm5VzSQNsww7h0CA05 tOtqIazOptZvLnTZhh5D9pLAZi3JgbkpPFv6j4sdRoC/Bac34wV2SGhN8vkoOfb/tYPq ewH0OUHQUDsMSGOcTn7TC6gOn9YhP9PZYwPNxreIjgneButoxIcIrWGZ29AUtbxW/mTW L2Rw== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=mJY40eSrutSDjBtN0H3A1ltvmot2BwE89aGMOSFi5ec=; b=cmoP2Srzy50qe45Efw7JyXmsYp4iXu0XLaEzwu2106D0uT5CBimIathFzjxUN8kEES SRoAFnmIBHcfOtyfW7c4BY2mqZahXmc5u65YVcs42COmPZsOZBq7FjB6phjDV27sPXFV zDNF4cbRT/TsrJzAWJtCAXmSD1P5/GdphFyijRM+ibQO7Fh7nKTuyKzTSyAPf2SdCvmE OaJM+45/UfOfUEbulJg6NZxFoLpY0Xqjs3EK55UEPvwZsB91oelrRA6i1+TSk2sr1Mct Ep7wVwfOzQ0AWwG9VE3himiOnTDtWlpeGpr3N7Ttty2Vm8xqOCXq9Bq+ucdNI2cRCH8+ PY/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ETAWNp3G; 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 o10si11790530ejj.111.2020.07.05.05.06.22; Sun, 05 Jul 2020 05:06:45 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ETAWNp3G; 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 S1726779AbgGEMET (ORCPT + 99 others); Sun, 5 Jul 2020 08:04:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:59464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726454AbgGEMET (ORCPT ); Sun, 5 Jul 2020 08:04:19 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 8612D20720; Sun, 5 Jul 2020 12:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593950658; bh=xElX9DIEPWBIPNDGxqYSPWbTFAH+JqylYPH3jjP06p0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ETAWNp3GiDl1HL3EWbbtWa0geFnXEExjcnjBLZSWwm4hFos38WH5+boqIDQp3/2lh 1r4NpWa+h9bmtw8LNTEetVNV7uYwwg6gzloBTFTRP+EPstbvznQacNP/PxylqP4dg9 GFw0BWd5h7sRxeFduUDZG9JRcXoFhpNU+/0jr0hc= Date: Sun, 5 Jul 2020 13:04:14 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: , , , , , Subject: Re: [PATCH 1/3] iio: adc: ti_am335x_adc: alloc channels via devm_kcalloc() Message-ID: <20200705130414.0aa2ac9b@archlinux> In-Reply-To: <20200428111430.71723-1-alexandru.ardelean@analog.com> References: <20200428111430.71723-1-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 28 Apr 2020 14:14:28 +0300 Alexandru Ardelean wrote: > This change attaches the life-cycle of the channels array to the parent > device object that is attached to the IIO device. > This way we can remove from the cleanup code, the explicit > tiadc_channels_remove() which simply does a kfree() on the channels array. > > Signed-off-by: Alexandru Ardelean Still not sure on patch 3 but I'll pick up the first 2 so we can forget about those. Applied to the togreg branch of iio.git and pushed out as testing for all the usual reasons. Thanks, Jonathan > --- > > The reason I'm targetting this driver, is because it's among the few > places where 'indio_dev->buffer' is accessed directly in the driver, and > that makes it difficult to think of a sane-backwards-compatible way to > do multiple IIO buffers. > > drivers/iio/adc/ti_am335x_adc.c | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) > > diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c > index 9d984f2a8ba7..d932fe383a24 100644 > --- a/drivers/iio/adc/ti_am335x_adc.c > +++ b/drivers/iio/adc/ti_am335x_adc.c > @@ -428,7 +428,8 @@ static const char * const chan_name_ain[] = { > "AIN7", > }; > > -static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) > +static int tiadc_channel_init(struct device *dev, struct iio_dev *indio_dev, > + int channels) > { > struct tiadc_device *adc_dev = iio_priv(indio_dev); > struct iio_chan_spec *chan_array; > @@ -436,7 +437,8 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) > int i; > > indio_dev->num_channels = channels; > - chan_array = kcalloc(channels, sizeof(*chan_array), GFP_KERNEL); > + chan_array = devm_kcalloc(dev, channels, sizeof(*chan_array), > + GFP_KERNEL); > if (chan_array == NULL) > return -ENOMEM; > > @@ -459,11 +461,6 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) > return 0; > } > > -static void tiadc_channels_remove(struct iio_dev *indio_dev) > -{ > - kfree(indio_dev->channels); > -} > - > static int tiadc_read_raw(struct iio_dev *indio_dev, > struct iio_chan_spec const *chan, > int *val, int *val2, long mask) > @@ -635,7 +632,7 @@ static int tiadc_probe(struct platform_device *pdev) > tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD); > mutex_init(&adc_dev->fifo1_lock); > > - err = tiadc_channel_init(indio_dev, adc_dev->channels); > + err = tiadc_channel_init(&pdev->dev, indio_dev, adc_dev->channels); > if (err < 0) > return err; > > @@ -666,7 +663,6 @@ static int tiadc_probe(struct platform_device *pdev) > err_buffer_unregister: > tiadc_iio_buffered_hardware_remove(indio_dev); > err_free_channels: > - tiadc_channels_remove(indio_dev); > return err; > } > > @@ -684,7 +680,6 @@ static int tiadc_remove(struct platform_device *pdev) > } > iio_device_unregister(indio_dev); > tiadc_iio_buffered_hardware_remove(indio_dev); > - tiadc_channels_remove(indio_dev); > > step_en = get_adc_step_mask(adc_dev); > am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);