From patchwork Thu Nov 7 19:18:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13866980 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011009.outbound.protection.outlook.com [52.101.70.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9473217668 for ; Thu, 7 Nov 2024 19:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007152; cv=fail; b=ctlV0JlZnAOeo1Lrl650DyXWRXTqiDGeKJ4TENd8gK7XpEeDQPTLZzVIqNLAOMdiOySVo+xHJrLvwI4KCfum+6DXUWvtwmYfMPM3pI8Ws+SzR4YfjpnoSQL8hgSOOsiUTr5VlNiylG5Q0o5Elbzd0FRT49C8hFwvSewYGUv3grs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007152; c=relaxed/simple; bh=WzwTTmhZpwi2/Zk49REqU4gHY3063pgo/Y/nMTNgnG8=; h=From:To:Subject:Date:Message-Id:Content-Type:MIME-Version; b=V0H0rdt9rQC/1LDaOKDZkhu7pC8FtmkEMWYHMTqxhytON9E5K8Qem6Os8KsoYipT29CdROei3oLDeqCHy5N2ByzAb2KYcoksntU6nuqKpRbiZK3Wvh8fHsroJCRpYF/nQlIW5lJm2Aqjyx+tat8tvYRIPlK/tB0sNioiFi1Qhu8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=NX1zAH8Q; arc=fail smtp.client-ip=52.101.70.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="NX1zAH8Q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sJpiDzZDTlNZy4+EBHFWlozUgpgMC6x2ULSk0VvpkjRKgV0O5h0ZnoYj2qnH5Y+uP5HMfhhNjs5XqTkBPF0OVkD749CEF4QyNZgfJKHqe+LOWoiXBV7AU8Cx8Z72Lt6d8O+cXnzed/Sc9u5rtQvmrOZcmux6chBB34h0J87XaAj4EaXcLcBPDpIm+SE8e/7LLJz2WsEJkOYJGecBB8GPAFCrE0BZ2E6G97NHVakOn/vBnd+sLvkQ48+kHBsyEoo9Uckw+6T0QjztNDoygFk59kmeiLaVnPj2TsZJS/fs/EjJIMimalUWqNI4KjYSepxmUWnHc8Yfi+vVzyeQov7zUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1fSAYRH83AS81M2WlpU5dBTKmFwXkIfbJe1h1KHu6uk=; b=VhfHTf/uzVq5nXojiJ9NJX6BcSlH7V4/ps96/i7O3eLtpq+uw8eD2dRDYcjk2qEiqo/EOfqWkz6JRN4dlJln1i7B9SYGeWkVzAfLV5sC/19288/sfKpRiTSQCqns44BVInYk/bVbKY6Fp6vUSVXLVXeEd6Cl7c5GLwAR8MZ+re6iDNrOjddkvX1qxJsFlKJvNKL0QoJxdPUbYSrL147HLHmkbTLfdACVLUe4Xg1TlSgCK5RYAdJPkMSNXRP7KoyDJPbx14edamfKiNfZ20S994PLD3jYZTyEug+5gnOYNzO+iA4tHi/cs3eynW8FZJdpJw5IQAU6/gj4/o05aDmRIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1fSAYRH83AS81M2WlpU5dBTKmFwXkIfbJe1h1KHu6uk=; b=NX1zAH8Q8MosDg52MaNOvE0r/68ybqO6kS1HjpzKfqI3q3VzrrfGmGqMJazjPDY1qrESB5BEug7DwOMBdU5AsCOGOocl/6T1DVR08bd9pCbmSiZN2HwFjl5oCRQfBOrcEs4YNhRzl8Sfyr726X07vb7UTsxs2cMBgqBHZ35CP7eI2WKAbbOVRESy4AN/0JPDtulKKUxSHdq2/2o7HF7SxZsyZ5eHL6He7UZES4FJielmnzDzpvEGBV+MWtT/Bp8c/LBkYZ051Su37kfI7dRrYx3PC4a1NzVbQ+Eli3goIgfuu77EizdC5/pqKIJqfw0ThgDY2T5EtjrDxc5DOl9sSw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB8344.eurprd04.prod.outlook.com (2603:10a6:20b:3b3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.19; Thu, 7 Nov 2024 19:18:56 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.018; Thu, 7 Nov 2024 19:18:56 +0000 From: Frank Li To: Haibo Chen , Jonathan Cameron , Lars-Peter Clausen , linux-iio@vger.kernel.org (open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER), imx@lists.linux.dev (open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Date: Thu, 7 Nov 2024 14:18:40 -0500 Message-Id: <20241107191842.3002319-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB8344:EE_ X-MS-Office365-Filtering-Correlation-Id: 63e4d5d7-68ba-45f4-2d47-08dcff610672 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: gVzvyWZriEqAuQ4x42O9/+k8VTN7wrCWpgGQXp0Gw7r79bE9oZ7o9MXijE9Jv/h9LGsxZCC0Is5eq22ZmmhosZdiji49dDmnHECsJEeDeSNVJ7W8O3uTri9w4qtxP8A36T5U9mzF6tFVbQ0kxZyrAgbAq+mbfqZOZmnmMSuQeqSPWFObbnsfCZEb9opCgACbb0+vnswF/RXlbUqrXB6HWk+bUX2WsHbkgLJhB6JT0BYOEODRGjAU6hO1ngUK4WnwKr9pNvj67SqtteZRD5Nw+eO6hKM1JJiNJtc8ZIxvHCKgFGnh0+vxBtHTLYOGD63fzXjRV6VpzK+YF4czYZubxHK2z+zcv4qFhOI06eE/ocIQ44wqBDjobPPaQ20Tw9PgfHP8JfkXoqpuzHwL7PHt319O8a4A0z2FTtb2+o1tYNgNrSCeLZG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8dPGMRW1m39zHU8M00YYO8Gfr/uTPbx0TOc+yzeQNE3JmkXsCliPQDFWzq3TMSa2QXM7oxOrdYrMpK44Z8rZWo27SHlQ1QPUDaRBwtLSfOsu15M0g8fJckxIaqYGH/KGgPqy2JDfMBu+Z6UIKLnnzzlbo9xoF/ui85Y/pqSfhjtnzes8vKb/JskGMrK9nuvEt159g4OTYr0rL6bpBrlYIadYC8SJ0v7oBYKhPvrxhpUWehPcazW7xZX2ZPBp4gCGnUFJvoZbUrZftsK210bCWkoUnQkTVNbM2lOHbm/7WyHkNDvXsBRuHQSN9DsWrJFUnW0OMIj/I7e3Waq98Z9ZuVqtjLPndaqqiROBBhNeQE/rhlXTnz9Ydf2zBqn5/hJX8UhFfcLPYGE9H3czSluKeKYdUYmVkp9N96aN5oH2ED+TS3Hom+T45UsIr1+kuZH+529T7yJzkgxfJ+pQwY5Pj+gg3uNvq4btse84IIgp/kvhDS6zf1mWBxwiD3R/UA2miWHkqiS1mg9b9rSPoGqBWw9aIPnKTzoEmxNlagLclYNPLoP6xbV4mCvzrGCPbPSY4yDk+bW6AUvjzMreWbYna7teuT+PmQvNMvNPr/41iuAWmjMaGXTdYIFOh7vO+4d9wxbRpLB0z5yVMz4a X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63e4d5d7-68ba-45f4-2d47-08dcff610672 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 19:18:56.7128 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ox3dDZCqCw8KtaNc7TOJLdKFxQ1Ye5vJXJel91Ln4jwjGUCVEyDsZrhF/mJxvqIHCc1/CNZmCxVjGfvQeWTTWA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8344 Use devm_* and dev_err_probe() simplify probe function and remove vf610_adc_remove(). Change type of 'vref_uv' to int because regulator_get_voltage() return type is int. Reviewed-by: Haibo Chen Signed-off-by: Frank Li --- Change from v2 to v3 - change vref_uv to int from u32 to fix below warning | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202411070633.NIrO7Ert-lkp@intel.com/ smatch warnings: drivers/iio/adc/vf610_adc.c:857 vf610_adc_probe() warn: unsigned 'info->vref_uv' is never less than zero. vim +857 drivers/iio/adc/vf610_adc.c Change from v1 to v2 - add Haibo's review tag --- drivers/iio/adc/vf610_adc.c | 79 ++++++++++--------------------------- 1 file changed, 20 insertions(+), 59 deletions(-) diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c index 4d83c12975c53..a6a0ada8a102f 100644 --- a/drivers/iio/adc/vf610_adc.c +++ b/drivers/iio/adc/vf610_adc.c @@ -160,7 +160,7 @@ struct vf610_adc { /* lock to protect against multiple access to the device */ struct mutex lock; - u32 vref_uv; + int vref_uv; u32 value; struct regulator *vref; @@ -823,10 +823,8 @@ static int vf610_adc_probe(struct platform_device *pdev) int ret; indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc)); - if (!indio_dev) { - dev_err(&pdev->dev, "Failed allocating iio device\n"); - return -ENOMEM; - } + if (!indio_dev) + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n"); info = iio_priv(indio_dev); info->dev = &pdev->dev; @@ -842,27 +840,22 @@ static int vf610_adc_probe(struct platform_device *pdev) ret = devm_request_irq(info->dev, irq, vf610_adc_isr, 0, dev_name(&pdev->dev), indio_dev); - if (ret < 0) { - dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq); - return ret; - } + if (ret < 0) + dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq); - info->clk = devm_clk_get(&pdev->dev, "adc"); - if (IS_ERR(info->clk)) { - dev_err(&pdev->dev, "failed getting clock, err = %ld\n", - PTR_ERR(info->clk)); - return PTR_ERR(info->clk); - } + info->clk = devm_clk_get_enabled(&pdev->dev, "adc"); + if (IS_ERR(info->clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), + "failed getting clock, err = %ld\n", + PTR_ERR(info->clk)); info->vref = devm_regulator_get(&pdev->dev, "vref"); if (IS_ERR(info->vref)) return PTR_ERR(info->vref); - ret = regulator_enable(info->vref); - if (ret) - return ret; - - info->vref_uv = regulator_get_voltage(info->vref); + info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref"); + if (info->vref_uv < 0) + return info->vref_uv; device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3); @@ -879,52 +872,21 @@ static int vf610_adc_probe(struct platform_device *pdev) indio_dev->channels = vf610_adc_iio_channels; indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels); - ret = clk_prepare_enable(info->clk); - if (ret) { - dev_err(&pdev->dev, - "Could not prepare or enable the clock.\n"); - goto error_adc_clk_enable; - } - vf610_adc_cfg_init(info); vf610_adc_hw_init(info); - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, - NULL, &iio_triggered_buffer_setup_ops); - if (ret < 0) { - dev_err(&pdev->dev, "Couldn't initialise the buffer\n"); - goto error_iio_device_register; - } + ret = devm_iio_triggered_buffer_setup(&pdev->dev, indio_dev, &iio_pollfunc_store_time, + NULL, &iio_triggered_buffer_setup_ops); + if (ret < 0) + return dev_err_probe(&pdev->dev, ret, "Couldn't initialise the buffer\n"); mutex_init(&info->lock); - ret = iio_device_register(indio_dev); - if (ret) { - dev_err(&pdev->dev, "Couldn't register the device.\n"); - goto error_adc_buffer_init; - } + ret = devm_iio_device_register(&pdev->dev, indio_dev); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Couldn't register the device.\n"); return 0; - -error_adc_buffer_init: - iio_triggered_buffer_cleanup(indio_dev); -error_iio_device_register: - clk_disable_unprepare(info->clk); -error_adc_clk_enable: - regulator_disable(info->vref); - - return ret; -} - -static void vf610_adc_remove(struct platform_device *pdev) -{ - struct iio_dev *indio_dev = platform_get_drvdata(pdev); - struct vf610_adc *info = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - regulator_disable(info->vref); - clk_disable_unprepare(info->clk); } static int vf610_adc_suspend(struct device *dev) @@ -972,7 +934,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, vf610_adc_suspend, static struct platform_driver vf610_adc_driver = { .probe = vf610_adc_probe, - .remove = vf610_adc_remove, .driver = { .name = DRIVER_NAME, .of_match_table = vf610_adc_match,