Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1078684pxb; Fri, 20 Nov 2020 00:00:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfYDvh+lM2rSWiJd8HW/dJvz5/zmG8mLY/B5IUF41jpLugSoVQIx75F43AEQ6YbSrViSAp X-Received: by 2002:a17:906:c059:: with SMTP id bm25mr10318983ejb.20.1605859237892; Fri, 20 Nov 2020 00:00:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605859237; cv=none; d=google.com; s=arc-20160816; b=lmBVFnuw2ge/ig9jCu0iKLg7JY3hfhKH08hM2uDWpFmoncP/t35w7rcCAaEnCKYdNW Gr1a1N+22Q6osc+zfWdzAe/NI32A2ZsteXUMyfDO3QUlwzKGCEQocGaaX3DDBLyuak6X G+Of8Zm0i6vun9xYI9+NOZfHojdbu8M/0LnNmrtH/6k1XDrjkMY7TqgDrx9/7gIrAaSF EgKmk3Rpe3u9CRj3XRN1lL7uRIl2OZ1nDfC8I3KoY6duhzGi9joY1YlRR5upAzdRX5z0 3hphMmz2gDxi3cf3sQaYzorAOn5irs90YYuZaebNwd6DdV7xOBcMwle3GKCfk34vWBVk xHqg== 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; bh=ReomKgh9MbOLfNjvvaiSX2qWlv6IWxaxzsdV5INJ398=; b=ObJTVILX/J/InZquoIumB5npxcNGkuZZjsersCIF6eNwXfGsOGY9SXAIKXxD4kGGgd rbUvcbTalyP4aZtmk/0/L9zQVLlukqCJw5qmqbJfh80fnAugraJyAvrkFoaPTG5uX00j UK5DiAtyE+RlQMXs26GMCGSsu6yLzq4suaFfydNhTN8mAIrnscdNiNzUY6gfuoKMYGjs H/Nt+l0gyz19tR14raGXx4Q9uu6WpGhlHoYOG0QF+C2lhZmEqmqqMxV/tjx5eSDW9VY1 RmomwoinmjGBc64qGpeyR52j7+Y/UWlsMaB/d0UWO+Oc7g5phApU3t5/dH9cKgmh4p4a flxA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x17si1547478edq.475.2020.11.20.00.00.14; Fri, 20 Nov 2020 00:00:37 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727063AbgKTH4j (ORCPT + 99 others); Fri, 20 Nov 2020 02:56:39 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:13040 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726673AbgKTH4h (ORCPT ); Fri, 20 Nov 2020 02:56:37 -0500 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AK7rfi4019313; Fri, 20 Nov 2020 02:56:36 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 34td19n60a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Nov 2020 02:56:36 -0500 Received: from SCSQMBX11.ad.analog.com (SCSQMBX11.ad.analog.com [10.77.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 0AK7uYaH034920 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Fri, 20 Nov 2020 02:56:35 -0500 Received: from SCSQMBX10.ad.analog.com (10.77.17.5) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Thu, 19 Nov 2020 23:56:33 -0800 Received: from zeus.spd.analog.com (10.66.68.11) by SCSQMBX10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Thu, 19 Nov 2020 23:56:33 -0800 Received: from saturn.ad.analog.com ([10.48.65.107]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 0AK7uUcs017423; Fri, 20 Nov 2020 02:56:30 -0500 From: Alexandru Ardelean To: CC: , Alexandru Ardelean Subject: [PATCH 1/2] uio: uio_dmem_genirq: convert simple allocations to device-managed Date: Fri, 20 Nov 2020 09:56:24 +0200 Message-ID: <20201120075625.12272-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-20_03:2020-11-19,2020-11-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=1 impostorscore=0 mlxscore=0 malwarescore=0 adultscore=0 clxscore=1015 phishscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011200051 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change converts the simple allocations in the driver to used device-managed allocation functions. This removes the error path entirely in the probe function, and reduces some code in the remove function. Signed-off-by: Alexandru Ardelean --- drivers/uio/uio_dmem_genirq.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/drivers/uio/uio_dmem_genirq.c b/drivers/uio/uio_dmem_genirq.c index ec7f66f4555a..72aa372d6ba6 100644 --- a/drivers/uio/uio_dmem_genirq.c +++ b/drivers/uio/uio_dmem_genirq.c @@ -154,11 +154,10 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) if (pdev->dev.of_node) { /* alloc uioinfo for one device */ - uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL); + uioinfo = devm_kzalloc(&pdev->dev, sizeof(*uioinfo), GFP_KERNEL); if (!uioinfo) { - ret = -ENOMEM; dev_err(&pdev->dev, "unable to kmalloc\n"); - goto bad2; + return -ENOMEM; } uioinfo->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn", pdev->dev.of_node); @@ -167,20 +166,19 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) if (!uioinfo || !uioinfo->name || !uioinfo->version) { dev_err(&pdev->dev, "missing platform_data\n"); - goto bad0; + return -EINVAL; } if (uioinfo->handler || uioinfo->irqcontrol || uioinfo->irq_flags & IRQF_SHARED) { dev_err(&pdev->dev, "interrupt configuration error\n"); - goto bad0; + return -EINVAL; } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) { - ret = -ENOMEM; dev_err(&pdev->dev, "unable to kmalloc\n"); - goto bad0; + return -ENOMEM; } dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); @@ -197,7 +195,7 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) if (ret == -ENXIO && pdev->dev.of_node) ret = UIO_IRQ_NONE; else if (ret < 0) - goto bad1; + return ret; uioinfo->irq = ret; } @@ -286,19 +284,11 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) if (ret) { dev_err(&pdev->dev, "unable to register uio device\n"); pm_runtime_disable(&pdev->dev); - goto bad1; + return ret; } platform_set_drvdata(pdev, priv); return 0; - bad1: - kfree(priv); - bad0: - /* kfree uioinfo for OF */ - if (pdev->dev.of_node) - kfree(uioinfo); - bad2: - return ret; } static int uio_dmem_genirq_remove(struct platform_device *pdev) @@ -308,14 +298,6 @@ static int uio_dmem_genirq_remove(struct platform_device *pdev) uio_unregister_device(priv->uioinfo); pm_runtime_disable(&pdev->dev); - priv->uioinfo->handler = NULL; - priv->uioinfo->irqcontrol = NULL; - - /* kfree uioinfo for OF */ - if (pdev->dev.of_node) - kfree(priv->uioinfo); - - kfree(priv); return 0; } -- 2.27.0