From patchwork Wed Oct 17 19:24:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 10646023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A3C03112B for ; Wed, 17 Oct 2018 19:24:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E8F528848 for ; Wed, 17 Oct 2018 19:24:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F73828891; Wed, 17 Oct 2018 19:24:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8434D28848 for ; Wed, 17 Oct 2018 19:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728284AbeJRDVY (ORCPT ); Wed, 17 Oct 2018 23:21:24 -0400 Received: from smtpo.poczta.interia.pl ([217.74.65.157]:56584 "EHLO smtpo.poczta.interia.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727128AbeJRDVY (ORCPT ); Wed, 17 Oct 2018 23:21:24 -0400 X-Interia-R: Interia X-Interia-R-IP: 188.121.17.172 X-Interia-R-Helo: Received: from x220.localdomain (ipv4-188-121-17-172.net.internetunion.pl [188.121.17.172]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 17 Oct 2018 21:24:08 +0200 (CEST) Date: Wed, 17 Oct 2018 21:24:29 +0200 From: Slawomir Stepien To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 1/1] staging: iio: adc: ad7280a: use devm_* APIs Message-ID: <20181017192429.GB6085@x220.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1539804250; bh=M5V4E3TcUCCl6x/Sh/4F7SilODHFuPBwH3JC4PrvHqA=; h=X-Interia-R:X-Interia-R-IP:X-Interia-R-Helo:Date:From:To:Cc: Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition: User-Agent:X-Interia-Antivirus; b=W8qC+Frmnl3Tx99RldY0nvfAA5PyS5yBD2r+xmk7ZMosAX77+KHmZRiduTi3GWnMz F9EaXLTuuHaYMGwI5kT9FylPa+StJAgO6dNmW1hkOAZsC4bJdmq0O2EfigP2uNdNKW HQjxp0RMr6ipuroWVQX7jTTcR4UncOFax73EaS8c= Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP devm_* APIs are device managed and make code simpler. Signed-off-by: Slawomir Stepien --- drivers/staging/iio/adc/ad7280a.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index b736275c10f5..cbb67f1230c7 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -492,8 +491,8 @@ static int ad7280_channel_init(struct ad7280_state *st) { int dev, ch, cnt; - st->channels = kcalloc((st->slave_num + 1) * 12 + 2, - sizeof(*st->channels), GFP_KERNEL); + st->channels = devm_kcalloc(&st->spi->dev, (st->slave_num + 1) * 12 + 2, + sizeof(*st->channels), GFP_KERNEL); if (!st->channels) return -ENOMEM; @@ -553,9 +552,9 @@ static int ad7280_attr_init(struct ad7280_state *st) { int dev, ch, cnt; - st->iio_attr = kcalloc(2, sizeof(*st->iio_attr) * - (st->slave_num + 1) * AD7280A_CELLS_PER_DEV, - GFP_KERNEL); + st->iio_attr = devm_kcalloc(&st->spi->dev, 2, sizeof(*st->iio_attr) * + (st->slave_num + 1) * AD7280A_CELLS_PER_DEV, + GFP_KERNEL); if (!st->iio_attr) return -ENOMEM; @@ -692,7 +691,8 @@ static irqreturn_t ad7280_event_handler(int irq, void *private) unsigned int *channels; int i, ret; - channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL); + channels = devm_kcalloc(&st->spi->dev, st->scan_cnt, sizeof(*channels), + GFP_KERNEL); if (!channels) return IRQ_HANDLED; @@ -744,7 +744,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private) } out: - kfree(channels); + devm_kfree(&st->spi->dev, channels); return IRQ_HANDLED; } @@ -909,11 +909,11 @@ static int ad7280_probe(struct spi_device *spi) ret = ad7280_attr_init(st); if (ret < 0) - goto error_free_channels; + return ret; ret = iio_device_register(indio_dev); if (ret) - goto error_free_attr; + return ret; if (spi->irq > 0) { ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, @@ -944,12 +944,6 @@ static int ad7280_probe(struct spi_device *spi) error_unregister: iio_device_unregister(indio_dev); -error_free_attr: - kfree(st->iio_attr); - -error_free_channels: - kfree(st->channels); - return ret; } @@ -965,9 +959,6 @@ static int ad7280_remove(struct spi_device *spi) ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); - kfree(st->channels); - kfree(st->iio_attr); - return 0; }