Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3537284pxv; Mon, 28 Jun 2021 06:55:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuh7nC4zaEHrhTc8zXQSdzji6BptR+ygram+PUWwgmjbEuMd/XmU899OdLP8aVvgV7DYeG X-Received: by 2002:a17:906:b7cb:: with SMTP id fy11mr24343328ejb.189.1624888555754; Mon, 28 Jun 2021 06:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624888555; cv=none; d=google.com; s=arc-20160816; b=YIVZqvotRkZsJNAMRR9IEDMvOc266deoifBevPaaEQrCKj4TAeMxO9TXRKF3xlBM2g b8rDXkzgH5OQGkrhXxpAE4fphPP5Jg95nFbYghHMXqWkD1JRmH6v00jcTpN/wbSvJgjx dcCOszK/HYYYuoDYUU6pM2Q/ANXsz7pD76pczKzVn/EjYYNpW0y0zUeowQbmLybpJnOY p/qYnd1qCklzv7XIPr4TsIHABvbvoLt8TaMquFvarh2JzHM56jmT07kOxISBjVwjuiuO Px5O6Zd/4GWJXgZIaOGQwXxs93MrdRfz0K3yBn6D/YJdDMicQaA5EPabggF9LmHWTXA4 XLig== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=diap9fcYCkWKv/Qg6fT0+qsnz8jKwEg8akmh3ZI+4Wg=; b=IZa4mchA+kepWAIeuaNqlbw5G3Ouez90xK8vLGGeZxMlu7CWvIxf3iGZB20vE6tai1 2uXE2qrCUmJmKx9gnNZDDiH6veWikI3HhhRRj7S3r/4adKb89BOFe/+DY6r7mf8boTNH O4xmfwtXH36epnIHyT90kH0W86ytGwcov01iJ2C3EX+DDkuJmIE6SNolSgqDnGZAOdwT CxazQ+iJXjD4gqUUJ5v1wBSHZDclFcsIqeruazGSMrpoK8VPXvTNKDx9iCHo1mXa7aMS cl0c4kWqnnq2fGE7qcdynlFqwr6RpRkK0SmSDzXKEHxHVU678ahGi8CKJcvJUXJJqgBO zfLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=G3jDBf5Y; 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=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si14035007ede.78.2021.06.28.06.55.30; Mon, 28 Jun 2021 06:55:55 -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=@deviqon.com header.s=google header.b=G3jDBf5Y; 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=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232065AbhF1Nyu (ORCPT + 99 others); Mon, 28 Jun 2021 09:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbhF1Nyr (ORCPT ); Mon, 28 Jun 2021 09:54:47 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE04CC061574 for ; Mon, 28 Jun 2021 06:52:21 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j1so21346973wrn.9 for ; Mon, 28 Jun 2021 06:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=diap9fcYCkWKv/Qg6fT0+qsnz8jKwEg8akmh3ZI+4Wg=; b=G3jDBf5YwwFNJ7E6BmB1nhbQZYlznqZSI/avLRaRxOIigRWmqDK6OxUOAjkeUTyRsS x+aVl9FGNYILNu537NoKMXZ7i93oB9P+eF8OfUUDv23GPn0x36Y9FJzmmyeZugdNfzDk 8+Ugkzj6Z5+uLuP3yh1ctb9kz9rCqy8SiHqcMFfOtkMYvxx5lfyoiWy0BDWipflaI6jP 4YztLc0XC14CnxoSJPhSNGEwVKEm2d8Hof8AzphX4MrbbmdlLWjXPR0C/pPjfMF/YXcc pfpWRZA2kPXtGUlF3jEjm6dNGjroakgt7G6gYNFvR3IbOA5mpONsPVQUC4WDjptBiqHo pjxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=diap9fcYCkWKv/Qg6fT0+qsnz8jKwEg8akmh3ZI+4Wg=; b=KFR0/1+CF23eXoCMr+ZavFY0r9KmjTvxcNrESiq4tT5/DcGSDA+Q159IzIi6jmPgof wnGzQawNrKWHeeACU8v92etXyMmqYO42G/NevgrQL4v2d4rzff8evlNk8T+RYJOETXFS jgdHymldVQM84g2bQ8loqRiPwu1+hNL7L9FOC+MKXGjaMq4zsL51xRZQUl0Ruvr4TPu9 tJ2aOyB9GTcAlGsGpE/1iJyvMG0MUodGus75c2/rnYOEDBWOsJu2BlMeWHZK8jwLAvHi j73db3pIpFVB0lToK+i3DYOCGc5K649QophwPBvNVCNQzk3dD99rulcEd+vOARqTq3AG RzSg== X-Gm-Message-State: AOAM533JYppPvv5SfQ5mNiKAKgkIuKQPn24H88E+mq7CXoGabthgR+cJ H1lsrDKFum2tkuociouLzNSNng== X-Received: by 2002:a5d:4103:: with SMTP id l3mr9365465wrp.102.1624888340356; Mon, 28 Jun 2021 06:52:20 -0700 (PDT) Received: from neptune.anevia.com (ip-149-62-159-73.naitways.net. [149.62.159.73]) by smtp.gmail.com with ESMTPSA id m184sm13749911wmm.26.2021.06.28.06.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 06:52:19 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Alexandru Ardelean Subject: [PATCH] iio: light: adjd_s311: convert to device-managed functions Date: Mon, 28 Jun 2021 16:51:32 +0300 Message-Id: <20210628135132.73682-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This one is a little easier to convert to device-managed, now with the devm_krealloc() function. The other iio_triggered_buffer_setup() and iio_device_register() can be converted to their devm_ variants. And devm_krealloc() can be used to (re)alloc the buffer. When the driver unloads, this will also be free'd. Signed-off-by: Alexandru Ardelean --- drivers/iio/light/adjd_s311.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c index 17dac8d0e11d..19d60d6986a1 100644 --- a/drivers/iio/light/adjd_s311.c +++ b/drivers/iio/light/adjd_s311.c @@ -230,8 +230,8 @@ static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev, { struct adjd_s311_data *data = iio_priv(indio_dev); - kfree(data->buffer); - data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); + data->buffer = devm_krealloc(indio_dev->dev.parent, data->buffer, + indio_dev->scan_bytes, GFP_KERNEL); if (data->buffer == NULL) return -ENOMEM; @@ -256,7 +256,6 @@ static int adjd_s311_probe(struct i2c_client *client, return -ENOMEM; data = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); data->client = client; indio_dev->info = &adjd_s311_info; @@ -265,34 +264,12 @@ static int adjd_s311_probe(struct i2c_client *client, indio_dev->num_channels = ARRAY_SIZE(adjd_s311_channels); indio_dev->modes = INDIO_DIRECT_MODE; - err = iio_triggered_buffer_setup(indio_dev, NULL, - adjd_s311_trigger_handler, NULL); + err = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, + adjd_s311_trigger_handler, NULL); if (err < 0) return err; - err = iio_device_register(indio_dev); - if (err) - goto exit_unreg_buffer; - - dev_info(&client->dev, "ADJD-S311 color sensor registered\n"); - - return 0; - -exit_unreg_buffer: - iio_triggered_buffer_cleanup(indio_dev); - return err; -} - -static int adjd_s311_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct adjd_s311_data *data = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - kfree(data->buffer); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } static const struct i2c_device_id adjd_s311_id[] = { @@ -306,7 +283,6 @@ static struct i2c_driver adjd_s311_driver = { .name = ADJD_S311_DRV_NAME, }, .probe = adjd_s311_probe, - .remove = adjd_s311_remove, .id_table = adjd_s311_id, }; module_i2c_driver(adjd_s311_driver); -- 2.31.1