From patchwork Mon Oct 26 13:36:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11857185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7377B139F for ; Mon, 26 Oct 2020 13:36:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51E352466D for ; Mon, 26 Oct 2020 13:36:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="ETNQ5C4O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1780245AbgJZNg0 (ORCPT ); Mon, 26 Oct 2020 09:36:26 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40389 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1780233AbgJZNgZ (ORCPT ); Mon, 26 Oct 2020 09:36:25 -0400 Received: by mail-wm1-f68.google.com with SMTP id k18so12467174wmj.5 for ; Mon, 26 Oct 2020 06:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oc+CRyq0MP1rGPx6qu4fJIiuXgNVzq5WpNvySKjLu6M=; b=ETNQ5C4O4Im+z0OFc2LmdOrgCbdwcTHV3i/sud6MR3r4APa/DibA2O/U7gKfdhQtcD GyAC8xb4Z1kpnIu1iiF7XUI3Brt3EafJsFgfgxnSrRFgXrBAJ/h35VjL/IZBqjBU36V9 7abLJobIJsHmrGESMQ9uBBYvHLfTAaxOU0L4xz+Iv3dR0QI48jjWKBNZv21Rnw3FnzPo BP1hBl+MYk949RWjY9XvWCr5WQM6IqnCuRTXiWPgJPZ4w7s1kozW/FJRw+iWdvYXMvBU mgsiWrgZfJOxqnfRlN96vgoRWjxogl/Ei1RrQe5WSMCzaID4NvAvXfnMMB35tqBNzrSn yE0w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=oc+CRyq0MP1rGPx6qu4fJIiuXgNVzq5WpNvySKjLu6M=; b=Ba+TgsBsdnqOUhgpnTl0Eh8mTUpgJ4Ai2wivSXGlfz3qecntro3AbCZusY6KTO5Dit YlK0pR9wtl2l7YdfZK4Zg7FUj24UY76xA9axvgst6I/pF8wh919ya/unPv7GvmHRm/xM mmZtS3TO53GCFUEeSCf5i1v7rV1+57Fs2eprCRUc8TiV4jLQ02VKE9pVximKr+XSmQ5A DuWg8hmmPNC4QGiV6QOOf1Xv/VC6rCO0Uw6MDmfc0lRdfVyftSPoufp0aNTIp84cb7Zl AzyJiKcmrWxSnTkmUdpO7952hB/TTrw7QjpJOd74hAVkcyiHIYHyXcukj5FUYkmFtL6j +4kQ== X-Gm-Message-State: AOAM532F0aTmHu7SAloNeIoBwnT5n6BlTPt8gfiNK6Ju1AG1TymIwGsy 28HufbN6ioogK+x/6Gv/pFl0kw== X-Google-Smtp-Source: ABdhPJxRBZnwVrN5mfPlZqgpI52Qd3hNu9GOYY/E9bIWA0MosamJ/tI/ASBpOEiIxMQWYBucoMAVUA== X-Received: by 2002:a1c:2601:: with SMTP id m1mr15236488wmm.12.1603719381363; Mon, 26 Oct 2020 06:36:21 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-190-206.w2-15.abo.wanadoo.fr. [2.15.39.206]) by smtp.gmail.com with ESMTPSA id f7sm23688991wrx.64.2020.10.26.06.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 06:36:20 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/5] iio: adc: xilinx: use helper variable for &pdev->dev Date: Mon, 26 Oct 2020 14:36:05 +0100 Message-Id: <20201026133609.24262-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201026133609.24262-1-brgl@bgdev.pl> References: <20201026133609.24262-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski It's more elegant to use a helper local variable to store the address of the underlying struct device than to dereference pdev everywhere. Signed-off-by: Bartosz Golaszewski --- drivers/iio/adc/xilinx-xadc-core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index f93c34fe5873..8494eb424b33 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -1186,6 +1186,7 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, static int xadc_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; const struct of_device_id *id; struct iio_dev *indio_dev; unsigned int bipolar_mask; @@ -1195,10 +1196,10 @@ static int xadc_probe(struct platform_device *pdev) int irq; int i; - if (!pdev->dev.of_node) + if (!dev->of_node) return -ENODEV; - id = of_match_node(xadc_of_match_table, pdev->dev.of_node); + id = of_match_node(xadc_of_match_table, dev->of_node); if (!id) return -EINVAL; @@ -1206,7 +1207,7 @@ static int xadc_probe(struct platform_device *pdev) if (irq <= 0) return -ENXIO; - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*xadc)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*xadc)); if (!indio_dev) return -ENOMEM; @@ -1226,7 +1227,7 @@ static int xadc_probe(struct platform_device *pdev) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &xadc_info; - ret = xadc_parse_dt(indio_dev, pdev->dev.of_node, &conf0); + ret = xadc_parse_dt(indio_dev, dev->of_node, &conf0); if (ret) return ret; @@ -1250,7 +1251,7 @@ static int xadc_probe(struct platform_device *pdev) } } - xadc->clk = devm_clk_get(&pdev->dev, NULL); + xadc->clk = devm_clk_get(dev, NULL); if (IS_ERR(xadc->clk)) { ret = PTR_ERR(xadc->clk); goto err_free_samplerate_trigger; @@ -1276,7 +1277,7 @@ static int xadc_probe(struct platform_device *pdev) } ret = request_irq(xadc->irq, xadc->ops->interrupt_handler, 0, - dev_name(&pdev->dev), indio_dev); + dev_name(dev), indio_dev); if (ret) goto err_clk_disable_unprepare; From patchwork Mon Oct 26 13:36:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11857183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92252697 for ; Mon, 26 Oct 2020 13:36:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7595F24641 for ; Mon, 26 Oct 2020 13:36:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="AE5uYd3q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1780247AbgJZNg0 (ORCPT ); Mon, 26 Oct 2020 09:36:26 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39585 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1775552AbgJZNg0 (ORCPT ); Mon, 26 Oct 2020 09:36:26 -0400 Received: by mail-wm1-f65.google.com with SMTP id d3so12501737wma.4 for ; Mon, 26 Oct 2020 06:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CjmXhl5JLo4J/PxFbte5j14dKUd6PJral95QAT5RzjQ=; b=AE5uYd3q/mN+YF+UoNFzyWfn2e6aNplcHY2J7LSmHYbHDV+AteEfF4NyzxqqRYZoBc n/H3yCCMtcPvc+nEf7l1mv8FXlr1u6Z4ulvrO6bNG5QpWlJOX47vTf9rnpKY9axYH6n2 Lzlc+XzrljZQ7kifz3e3pRSUIOy6S64I4iKJuRFuQNVTB/yLAIgOUqIc7ZB6+jmZZmYU GrFyTr66j9EF9wpV0uVqawEulSwlRpU4G8o2LU0rE1udCvyx0DV1kIEjDiG0YhykpLEd 4F4QKwsvlMIPm5ZU6OuSE8ElztOAfmqCVI07OgFG+S66sRWCr4pILeNQf+AedtxFXQZF uQ7g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=CjmXhl5JLo4J/PxFbte5j14dKUd6PJral95QAT5RzjQ=; b=Upuw6tdGmjcf2XhFzWr0Ire24O39qmLUb4ZG8a4w1MWG4WoPT7ezFaeRVOUw2Em/a5 LP8tq73MDK01nL0naO+aRYVaQm2dzI+JivUR30q8vynMkEioywowoVT8wwYCiNO3vBvb Lst/iO1mQYdLsVoeGXRDgHVJa0ZuadOV9GQoHXusDCwLKUp32p4GyMDUoxxaa6AuuWG8 weYQFhFO2LXxx0pqDevPBJLMqwZ0Rvg5j30Fawabd3l8oyug5atNlbnoiHu5Wnsaqz9T ukqPkHXV0sTC8bqLcjJW1aE6THK0zGdBAj07QtHNS3+06k+lZO4fJ3w7c/bqYQ/O/o9l WSaw== X-Gm-Message-State: AOAM532LwlYuwT/ebRVbBiB/lY5opec7CMZLDAoTZD+iOYEEGTaGsXh+ kHLxiokyafbZW3WZf6H+exEZtw== X-Google-Smtp-Source: ABdhPJyx5XmliVgkj2HH8RoBGVNGyWBgD1WUqyjfZC8wakM0iZX/XJLYW/tw3KdwIN2ATgE39WAaww== X-Received: by 2002:a1c:48c3:: with SMTP id v186mr17231235wma.16.1603719383782; Mon, 26 Oct 2020 06:36:23 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-190-206.w2-15.abo.wanadoo.fr. [2.15.39.206]) by smtp.gmail.com with ESMTPSA id f7sm23688991wrx.64.2020.10.26.06.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 06:36:23 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/5] iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc() Date: Mon, 26 Oct 2020 14:36:06 +0100 Message-Id: <20201026133609.24262-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201026133609.24262-1-brgl@bgdev.pl> References: <20201026133609.24262-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski We now have devm_krealloc() in the kernel Use it indstead of calling kfree() and kcalloc() separately. Signed-off-by: Bartosz Golaszewski --- drivers/iio/adc/xilinx-xadc-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 8494eb424b33..b516280ccbd4 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -589,8 +589,9 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev, n = bitmap_weight(mask, indio_dev->masklength); - kfree(xadc->data); - xadc->data = kcalloc(n, sizeof(*xadc->data), GFP_KERNEL); + xadc->data = devm_krealloc(indio_dev->dev.parent, xadc->data, + n * sizeof(*xadc->data), + GFP_KERNEL | __GFP_ZERO); if (!xadc->data) return -ENOMEM; @@ -1372,7 +1373,6 @@ static int xadc_remove(struct platform_device *pdev) free_irq(xadc->irq, indio_dev); cancel_delayed_work_sync(&xadc->zynq_unmask_work); clk_disable_unprepare(xadc->clk); - kfree(xadc->data); return 0; } From patchwork Mon Oct 26 13:36:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11857189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 91DA9697 for ; Mon, 26 Oct 2020 13:36:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 744EE22284 for ; Mon, 26 Oct 2020 13:36:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="BVb3ChlT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1775671AbgJZNg2 (ORCPT ); Mon, 26 Oct 2020 09:36:28 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35766 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1780241AbgJZNg1 (ORCPT ); Mon, 26 Oct 2020 09:36:27 -0400 Received: by mail-wm1-f65.google.com with SMTP id h22so1409926wmb.0 for ; Mon, 26 Oct 2020 06:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SXWR59MruOI4ftzXqa49n6gagW95FuEqQ5BRdlBW3D0=; b=BVb3ChlTrKd6RBLbM7FQM9prom3acrYkxX+BkBhdIp5YYz1kU5+7cXLDmQ2i7s+Dif Esu1jX49DCMdRmMs03hAYnBBBLUfCE1fdV4J4uDyTsEoM2PC6Uc+WZQPiN8yIGh1Ni4d A8oOGmUPlXHj8AwVEIu0HPwQDBhimy505MPCBUGYDB4fyeMv3bOCZsVEG20CKkE5hwRQ ym/uK5blzf5j074tXR6+Euos9aafumbqnueCOUHdoVkF9Nrvkz1NYRiyLZp/WatIzrnR Qp677pDVNjFTvL03E47ww4HVQkPB3DytSrBRLcaHtHQ/unzySoY/bIM3c7zm/QJ5xie3 fbzA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=SXWR59MruOI4ftzXqa49n6gagW95FuEqQ5BRdlBW3D0=; b=oD5BADlZHPfAUwLgxJc8OtuVwR8d+b91EY4c5oPy4KQEtt7MZ/HNw77ZdWE6u9gITJ ekZQEWbwZykzV6n+YLnxVYpOUCzWk9X0J0MMffWNj0QbXGiWoby9NW6L66QSAlnjmuAW DX46D7VbnUHIRIY0qHQk4Aj7pIU6723xrgKPpTjqJARf4wdVhDQkNDbPa8dhg+lFwcZj jUxXLD9voO8ubC/9XOflbgRiM3hjfNWYhLB7N4Zgi/q95o9YYCjHyiHRn9MzMY5EMB37 3VzPrl+h4ViMBsPnuZ+nbei8nlCbwnO1RT8915FpRdntnacrpZ9YCY4M096/yuZKeVZZ xWLA== X-Gm-Message-State: AOAM533PWTcLo6on9ut9vIsFzeIQTMpOtKHfRbhVaGywef7KGaXx4WhX 8KI/ti+p+NXYkgg1jnQjQ3GnpQ== X-Google-Smtp-Source: ABdhPJw6LD69F2GZpzdLF6iY8OEb0BrDX2HHqT/seQxWtD4xu+ljXFDFvPheo8jlC8zEpYAwcDhrSA== X-Received: by 2002:a7b:c401:: with SMTP id k1mr15804816wmi.120.1603719385163; Mon, 26 Oct 2020 06:36:25 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-190-206.w2-15.abo.wanadoo.fr. [2.15.39.206]) by smtp.gmail.com with ESMTPSA id f7sm23688991wrx.64.2020.10.26.06.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 06:36:24 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 3/5] iio: adc: xilinx: use a devres action to disable and unprepare the clock Date: Mon, 26 Oct 2020 14:36:07 +0100 Message-Id: <20201026133609.24262-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201026133609.24262-1-brgl@bgdev.pl> References: <20201026133609.24262-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski In order to simplify resource management and error paths in probe(), add a devm action that calls clk_disable_unprepare() at driver detach. Signed-off-by: Bartosz Golaszewski --- drivers/iio/adc/xilinx-xadc-core.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index b516280ccbd4..e0da6258092c 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -1185,6 +1185,13 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, return 0; } +static void xadc_clk_disable_unprepare(void *data) +{ + struct clk *clk = data; + + clk_disable_unprepare(clk); +} + static int xadc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1262,6 +1269,11 @@ static int xadc_probe(struct platform_device *pdev) if (ret) goto err_free_samplerate_trigger; + ret = devm_add_action_or_reset(dev, + xadc_clk_disable_unprepare, xadc->clk); + if (ret) + goto err_free_samplerate_trigger; + /* * Make sure not to exceed the maximum samplerate since otherwise the * resulting interrupt storm will soft-lock the system. @@ -1280,7 +1292,7 @@ static int xadc_probe(struct platform_device *pdev) ret = request_irq(xadc->irq, xadc->ops->interrupt_handler, 0, dev_name(dev), indio_dev); if (ret) - goto err_clk_disable_unprepare; + goto err_free_samplerate_trigger; ret = xadc->ops->setup(pdev, indio_dev, xadc->irq); if (ret) @@ -1344,8 +1356,6 @@ static int xadc_probe(struct platform_device *pdev) err_free_irq: free_irq(xadc->irq, indio_dev); cancel_delayed_work_sync(&xadc->zynq_unmask_work); -err_clk_disable_unprepare: - clk_disable_unprepare(xadc->clk); err_free_samplerate_trigger: if (xadc->ops->flags & XADC_FLAGS_BUFFERED) iio_trigger_free(xadc->samplerate_trigger); @@ -1372,7 +1382,6 @@ static int xadc_remove(struct platform_device *pdev) } free_irq(xadc->irq, indio_dev); cancel_delayed_work_sync(&xadc->zynq_unmask_work); - clk_disable_unprepare(xadc->clk); return 0; } From patchwork Mon Oct 26 13:36:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11857191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BF73697 for ; Mon, 26 Oct 2020 13:36:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFD62206DD for ; Mon, 26 Oct 2020 13:36:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="UnKuxJDL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1780220AbgJZNgs (ORCPT ); Mon, 26 Oct 2020 09:36:48 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34831 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1780249AbgJZNg2 (ORCPT ); Mon, 26 Oct 2020 09:36:28 -0400 Received: by mail-wr1-f68.google.com with SMTP id n15so12604705wrq.2 for ; Mon, 26 Oct 2020 06:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2ELZQG2NaQttMYr9kJgm589fBatjQILmOfzJPCuqc5Y=; b=UnKuxJDLDxWVkgZLJZaKbCEGY8XmPdeCTb13G4N7oB+0BCGxI2N1raabhO7DLxB9gt baq0L2TyGPLzvLPriFZb6iprKVze14yzvC2oi0IHGX0VQ7eIziDOOfHhkHGhjZ+/pG+J DRrMOkin1ClHgXmGdfzMQkZOEhyDXcwGJn1RODHk8RkTyLURuFYcdBZcIoVFMOUXQ6sW mqF8fDmb/NRHoxLyR/+p572ecPm48+Vr+2Wp7uqv6GIKKdaQHv3CoJXZADWcgXwgplrm rrowddeaQhtAnDT9f4njAIUti8jdp9hszOl0iCQEXAqh0vqql92EqKpeugFKcb07SoOa 8Lkw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2ELZQG2NaQttMYr9kJgm589fBatjQILmOfzJPCuqc5Y=; b=HDyCvWlHVr5eZVG5PjzUNegwodK0wUqROtDLKF4baDO+XcSx1on9Izp8gWNFalOZ8f pJBfZ9twYeY+BLZY/xsfSza9eF7hWVKOwiKxS9W1lgYPsukcBh2M9bHfAz0N3RQRIli0 VR7y3fL3OCh+k3tXyZmYFTYbyPAOmz2O4Kpfkn4JGd6PWLPQA/CF/qk7ggl3SGQ4zNuM /I1l8OfoPFAOGPL/m0FbYfaZnBYYVEeRovCVswBUVVgfRvdAkk7pBVlikuKTVOTeXH3O +D7ZrYAuYSKMrWVizLuj5arLGO+zUbSU3xgMjgW+28zczxggcxnmbtz5VyFY/o/o5W00 Ki8g== X-Gm-Message-State: AOAM531SwYEN6zA4bpuC0dB421Eu1WN8/Bly80DdjG0cCsBeQcHNlMPw 8X7rJQzvlXXdVI3sgF6KDd4tPlXOLIfxvQ== X-Google-Smtp-Source: ABdhPJxhDAD5/YV5fDmGymJd9GlecQXRex3X8eVcy0qKcqKJI+LHTdOXOv7purW24dthsFu4Ih1bUA== X-Received: by 2002:a5d:554b:: with SMTP id g11mr18112929wrw.370.1603719386608; Mon, 26 Oct 2020 06:36:26 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-190-206.w2-15.abo.wanadoo.fr. [2.15.39.206]) by smtp.gmail.com with ESMTPSA id f7sm23688991wrx.64.2020.10.26.06.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 06:36:25 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/5] iio: adc: xilinx: use devres for irq handling Date: Mon, 26 Oct 2020 14:36:08 +0100 Message-Id: <20201026133609.24262-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201026133609.24262-1-brgl@bgdev.pl> References: <20201026133609.24262-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski Further simplify the remove() callback and error paths in probe() by using the managed variant of request_irq() as well as using a devm action for cancelling the delayed work at driver detach. Signed-off-by: Bartosz Golaszewski --- drivers/iio/adc/xilinx-xadc-core.c | 35 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index e0da6258092c..4440b7a9bd36 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -1192,6 +1192,13 @@ static void xadc_clk_disable_unprepare(void *data) clk_disable_unprepare(clk); } +static void xadc_cancel_delayed_work(void *data) +{ + struct delayed_work *work = data; + + cancel_delayed_work_sync(work); +} + static int xadc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1289,14 +1296,19 @@ static int xadc_probe(struct platform_device *pdev) } } - ret = request_irq(xadc->irq, xadc->ops->interrupt_handler, 0, - dev_name(dev), indio_dev); + ret = devm_request_irq(dev, xadc->irq, xadc->ops->interrupt_handler, 0, + dev_name(dev), indio_dev); + if (ret) + goto err_free_samplerate_trigger; + + ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work, + &xadc->zynq_unmask_work); if (ret) goto err_free_samplerate_trigger; ret = xadc->ops->setup(pdev, indio_dev, xadc->irq); if (ret) - goto err_free_irq; + goto err_free_samplerate_trigger; for (i = 0; i < 16; i++) xadc_read_adc_reg(xadc, XADC_REG_THRESHOLD(i), @@ -1304,7 +1316,7 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_CONF0, conf0); if (ret) - goto err_free_irq; + goto err_free_samplerate_trigger; bipolar_mask = 0; for (i = 0; i < indio_dev->num_channels; i++) { @@ -1314,17 +1326,17 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_INPUT_MODE(0), bipolar_mask); if (ret) - goto err_free_irq; + goto err_free_samplerate_trigger; ret = xadc_write_adc_reg(xadc, XADC_REG_INPUT_MODE(1), bipolar_mask >> 16); if (ret) - goto err_free_irq; + goto err_free_samplerate_trigger; /* Disable all alarms */ ret = xadc_update_adc_reg(xadc, XADC_REG_CONF1, XADC_CONF1_ALARM_MASK, XADC_CONF1_ALARM_MASK); if (ret) - goto err_free_irq; + goto err_free_samplerate_trigger; /* Set thresholds to min/max */ for (i = 0; i < 16; i++) { @@ -1339,7 +1351,7 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i), xadc->threshold[i]); if (ret) - goto err_free_irq; + goto err_free_samplerate_trigger; } /* Go to non-buffered mode */ @@ -1347,15 +1359,12 @@ static int xadc_probe(struct platform_device *pdev) ret = iio_device_register(indio_dev); if (ret) - goto err_free_irq; + goto err_free_samplerate_trigger; platform_set_drvdata(pdev, indio_dev); return 0; -err_free_irq: - free_irq(xadc->irq, indio_dev); - cancel_delayed_work_sync(&xadc->zynq_unmask_work); err_free_samplerate_trigger: if (xadc->ops->flags & XADC_FLAGS_BUFFERED) iio_trigger_free(xadc->samplerate_trigger); @@ -1380,8 +1389,6 @@ static int xadc_remove(struct platform_device *pdev) iio_trigger_free(xadc->convst_trigger); iio_triggered_buffer_cleanup(indio_dev); } - free_irq(xadc->irq, indio_dev); - cancel_delayed_work_sync(&xadc->zynq_unmask_work); return 0; } From patchwork Mon Oct 26 13:36:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11857187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09701139F for ; Mon, 26 Oct 2020 13:36:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9AD1206DD for ; Mon, 26 Oct 2020 13:36:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="xULoTkoU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1780260AbgJZNgc (ORCPT ); Mon, 26 Oct 2020 09:36:32 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40631 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1780250AbgJZNga (ORCPT ); Mon, 26 Oct 2020 09:36:30 -0400 Received: by mail-wr1-f65.google.com with SMTP id h5so12557434wrv.7 for ; Mon, 26 Oct 2020 06:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k40eJc8Lhw98TUMyUtqdBZVrG65XsNSVzHSaCNt0jHc=; b=xULoTkoUGRbnpHi6ZghaIZ1Q5yiAkgzBSZomS+pZDERJpF71+9WHNz7PkKFZCppqnR E8TvUVRzJBWf61WOq6yMPk1rtsL/mjsrHd984WeDRag1X84yfn9JZ3/BUdFfpsyAhr9i r+3jGNJKjnN9NhccBQ3VVT/UqJwJoQO0rwTYfNAdIj3OK+AX71r8AOVUI8mt+ZO9CAjl crYeJmkgxX/876FoIJU0Li4C6oO8FT+cCgFCyan2kbT99hhNS3i2Q9r4i1ccDmqKiRT0 mMHQBprSDMOBi94y3N82AbCwRWdMXNsHegunbPSFZH3U49aHEKpZXieoIckKWFPib/GG 7/eg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=k40eJc8Lhw98TUMyUtqdBZVrG65XsNSVzHSaCNt0jHc=; b=uWSDpPQIq8kv5HXV/smfqpZ7s5fA1eIbB/h/hiSP5G+5BcqH5mW4Mibv953KG7Z7jE oJoAXSfa2g0Y/FQX9HQIg1IKrq1Njxl2faPPgtOheeM9ICIraTrDalCYEI9BA4eFr9be j+ngBKe3rPsTX6DcUFlSbFAYOHgPLYDebX6uN7IgKFQGdQxyLoizXmjQLlgNYR8htDJk E0Vv1Puyq5skbXPEbVO+ZKuq1FkJWkcLzMpldWslRFrBNpuRBIvJ/VAT46YPwf3F57pm Gl9vIrVnxS2lmvoIddl7Ek/kPoQ1fXHZjJjWJt+vNe3vh0311GwTpabJytFSP70n3WCb qiRw== X-Gm-Message-State: AOAM532XB3eRzwsIaekOvhF+/xDoSnI+IbAUI4wt648WTFVoEI8DKSFY MxTuC07H7zWJ49dKX069VNgeZg== X-Google-Smtp-Source: ABdhPJya7i/8CLwnUaaOp1aYoYaQe7iJhVlKyGV0P8+acTJoTJqeMcxGCcPsHQ982b6i6Dwhqn+clQ== X-Received: by 2002:a5d:5344:: with SMTP id t4mr17501589wrv.267.1603719387795; Mon, 26 Oct 2020 06:36:27 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-190-206.w2-15.abo.wanadoo.fr. [2.15.39.206]) by smtp.gmail.com with ESMTPSA id f7sm23688991wrx.64.2020.10.26.06.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 06:36:27 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 5/5] iio: adc: xilinx: use iio devres helpers Date: Mon, 26 Oct 2020 14:36:09 +0100 Message-Id: <20201026133609.24262-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201026133609.24262-1-brgl@bgdev.pl> References: <20201026133609.24262-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski Shrink the code by using devres variants of all iio routines. This allows us to entirely drop the remove() callback as well as significantly simplifies error paths in probe(). Signed-off-by: Bartosz Golaszewski --- drivers/iio/adc/xilinx-xadc-core.c | 97 ++++++++++-------------------- 1 file changed, 32 insertions(+), 65 deletions(-) diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 4440b7a9bd36..c17705205456 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -706,11 +706,12 @@ static const struct iio_trigger_ops xadc_trigger_ops = { static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev, const char *name) { + struct device *dev = indio_dev->dev.parent; struct iio_trigger *trig; int ret; - trig = iio_trigger_alloc("%s%d-%s", indio_dev->name, - indio_dev->id, name); + trig = devm_iio_trigger_alloc(dev, "%s%d-%s", indio_dev->name, + indio_dev->id, name); if (trig == NULL) return ERR_PTR(-ENOMEM); @@ -718,15 +719,11 @@ static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev, trig->ops = &xadc_trigger_ops; iio_trigger_set_drvdata(trig, iio_priv(indio_dev)); - ret = iio_trigger_register(trig); + ret = devm_iio_trigger_register(dev, trig); if (ret) - goto error_free_trig; + return ERR_PTR(ret); return trig; - -error_free_trig: - iio_trigger_free(trig); - return ERR_PTR(ret); } static int xadc_power_adc_b(struct xadc *xadc, unsigned int seq_mode) @@ -1247,39 +1244,35 @@ static int xadc_probe(struct platform_device *pdev) return ret; if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { - ret = iio_triggered_buffer_setup(indio_dev, - &iio_pollfunc_store_time, &xadc_trigger_handler, - &xadc_buffer_ops); + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + &iio_pollfunc_store_time, + &xadc_trigger_handler, + &xadc_buffer_ops); if (ret) return ret; xadc->convst_trigger = xadc_alloc_trigger(indio_dev, "convst"); - if (IS_ERR(xadc->convst_trigger)) { - ret = PTR_ERR(xadc->convst_trigger); - goto err_triggered_buffer_cleanup; - } + if (IS_ERR(xadc->convst_trigger)) + return PTR_ERR(xadc->convst_trigger); + xadc->samplerate_trigger = xadc_alloc_trigger(indio_dev, "samplerate"); - if (IS_ERR(xadc->samplerate_trigger)) { - ret = PTR_ERR(xadc->samplerate_trigger); - goto err_free_convst_trigger; - } + if (IS_ERR(xadc->samplerate_trigger)) + return PTR_ERR(xadc->samplerate_trigger); } xadc->clk = devm_clk_get(dev, NULL); - if (IS_ERR(xadc->clk)) { - ret = PTR_ERR(xadc->clk); - goto err_free_samplerate_trigger; - } + if (IS_ERR(xadc->clk)) + return PTR_ERR(xadc->clk); ret = clk_prepare_enable(xadc->clk); if (ret) - goto err_free_samplerate_trigger; + return ret; ret = devm_add_action_or_reset(dev, xadc_clk_disable_unprepare, xadc->clk); if (ret) - goto err_free_samplerate_trigger; + return ret; /* * Make sure not to exceed the maximum samplerate since otherwise the @@ -1288,27 +1281,28 @@ static int xadc_probe(struct platform_device *pdev) if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { ret = xadc_read_samplerate(xadc); if (ret < 0) - goto err_free_samplerate_trigger; + return ret; + if (ret > XADC_MAX_SAMPLERATE) { ret = xadc_write_samplerate(xadc, XADC_MAX_SAMPLERATE); if (ret < 0) - goto err_free_samplerate_trigger; + return ret; } } ret = devm_request_irq(dev, xadc->irq, xadc->ops->interrupt_handler, 0, dev_name(dev), indio_dev); if (ret) - goto err_free_samplerate_trigger; + return ret; ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work, &xadc->zynq_unmask_work); if (ret) - goto err_free_samplerate_trigger; + return ret; ret = xadc->ops->setup(pdev, indio_dev, xadc->irq); if (ret) - goto err_free_samplerate_trigger; + return ret; for (i = 0; i < 16; i++) xadc_read_adc_reg(xadc, XADC_REG_THRESHOLD(i), @@ -1316,7 +1310,7 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_CONF0, conf0); if (ret) - goto err_free_samplerate_trigger; + return ret; bipolar_mask = 0; for (i = 0; i < indio_dev->num_channels; i++) { @@ -1326,17 +1320,18 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_INPUT_MODE(0), bipolar_mask); if (ret) - goto err_free_samplerate_trigger; + return ret; + ret = xadc_write_adc_reg(xadc, XADC_REG_INPUT_MODE(1), bipolar_mask >> 16); if (ret) - goto err_free_samplerate_trigger; + return ret; /* Disable all alarms */ ret = xadc_update_adc_reg(xadc, XADC_REG_CONF1, XADC_CONF1_ALARM_MASK, XADC_CONF1_ALARM_MASK); if (ret) - goto err_free_samplerate_trigger; + return ret; /* Set thresholds to min/max */ for (i = 0; i < 16; i++) { @@ -1351,51 +1346,23 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i), xadc->threshold[i]); if (ret) - goto err_free_samplerate_trigger; + return ret; } /* Go to non-buffered mode */ xadc_postdisable(indio_dev); - ret = iio_device_register(indio_dev); + ret = devm_iio_device_register(dev, indio_dev); if (ret) - goto err_free_samplerate_trigger; + return ret; platform_set_drvdata(pdev, indio_dev); - return 0; - -err_free_samplerate_trigger: - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) - iio_trigger_free(xadc->samplerate_trigger); -err_free_convst_trigger: - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) - iio_trigger_free(xadc->convst_trigger); -err_triggered_buffer_cleanup: - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) - iio_triggered_buffer_cleanup(indio_dev); - - return ret; -} - -static int xadc_remove(struct platform_device *pdev) -{ - struct iio_dev *indio_dev = platform_get_drvdata(pdev); - struct xadc *xadc = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { - iio_trigger_free(xadc->samplerate_trigger); - iio_trigger_free(xadc->convst_trigger); - iio_triggered_buffer_cleanup(indio_dev); - } - return 0; } static struct platform_driver xadc_driver = { .probe = xadc_probe, - .remove = xadc_remove, .driver = { .name = "xadc", .of_match_table = xadc_of_match_table,