Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2310119ybh; Mon, 16 Mar 2020 00:21:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuFaa1KwiikytRGhOibHEAGL4WXU2kipCViFUy+4XUHjwAVjDu/uMDsTIzbcDFAkqGlEKKc X-Received: by 2002:a9d:75c9:: with SMTP id c9mr22739754otl.155.1584343286112; Mon, 16 Mar 2020 00:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584343286; cv=none; d=google.com; s=arc-20160816; b=lTj0x+jShV2sSMhRONluBxCAv6IzXQ0AueQDtpizn2Vqu4bektfnQqZkoI8hdDHk6y LDmkJn1uLgy/ZA7rYo8lkgBTzku7iBleQLKL/Z+7Uqr5kKuDwvFtXmx8k1f2ZRFMR627 Cw+YLrJkO2XabBROBqYV/OJjrkWO/QuT+f67A/Gbhm3zK/R6UKPc8YFLV2zzzFzSP7R2 hqXqK6zoH4z7k5VLauZjKPiPidfnCKDGah+wV1lsKFd7bHVizv+jEqsQPRpdIubHsO1c Y9ScG74gqsgbqWw3E3RYWlc1ss1twuwi2rLxrcFOvq+5n1wsDR1nj2F8KQ8OaNLvc4yo SVDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Yisa4qZBXogsjsu0UBUCrwgSHPoybqOn38y9aI+oMAQ=; b=AbwNGwDZSx67ffzx5EwWq3whAMrVhbPSbrr2w8+RDAyfyVIUbSskkYkq3tpKBY/qiO 0AN+oln5kdG92UBAIzm/H4qothM6f/kC/jNarkQPQXqyjsdOtsXjOuYghgmGIlUhX2OV 6NiPQuEkm9sZKsPlMk1QAsooQpxqNbmZj2ziOUISYVPfDpXno8FresUsxuwuIO+6BCi3 Udtw5XjfwI0BBKINoIY9iSraY5LqBJ/odCmGi8qoa8/AvKU+aOYyR+MQbiayU0wsWfwP h+HYCrdrVBKN75as1NS2d8ma9HNCR8TDsUYNmKk5UHJQutlcrUJGF78JhvDy/q7/MeHw V8ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=cThaAhey; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t22si9213850oth.211.2020.03.16.00.21.11; Mon, 16 Mar 2020 00:21:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=cThaAhey; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729767AbgCPHUr (ORCPT + 99 others); Mon, 16 Mar 2020 03:20:47 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:33044 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728120AbgCPHUr (ORCPT ); Mon, 16 Mar 2020 03:20:47 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 02G7KhLg012845; Mon, 16 Mar 2020 02:20:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1584343243; bh=Yisa4qZBXogsjsu0UBUCrwgSHPoybqOn38y9aI+oMAQ=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=cThaAheyHJ+EAotUZu9KeHnIO+DWyRdUTC6rVjqSrE+ScMlFRGn3F4x2XRkXJQABq EdHCiLd6GigEA84MMDEwswrCIaWRitdgsaOB6XsqE7qmDBa/ImOgzwqQvR06O8HnwY SR65BEC+q7sTETLFTR+Q66jbuoYtIDZed9oT9RE0= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 02G7KhTi112724 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 16 Mar 2020 02:20:43 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Mon, 16 Mar 2020 02:20:42 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Mon, 16 Mar 2020 02:20:42 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 02G7KepR117384; Mon, 16 Mar 2020 02:20:41 -0500 Subject: Re: [PATCH] dmaengine: ti: k3-udma: Fix an error handling path in 'k3_udma_glue_cfg_rx_flow()' To: Christophe JAILLET , , , CC: , , References: <20200315155015.27303-1-christophe.jaillet@wanadoo.fr> From: Peter Ujfalusi Message-ID: <49a35126-3cc6-0cbb-e632-42a237ef353e@ti.com> Date: Mon, 16 Mar 2020 09:20:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200315155015.27303-1-christophe.jaillet@wanadoo.fr> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christophe, On 15/03/2020 17.50, Christophe JAILLET wrote: > All but one error handling paths in the 'k3_udma_glue_cfg_rx_flow()' > function 'goto err' and call 'k3_udma_glue_release_rx_flow()'. > > This not correct because this function has a 'channel->flows_ready--;' at > the end, but 'flows_ready' has not been incremented here, when we branch to > the error handling path. > > In order to keep a correct value in 'flows_ready', un-roll > 'k3_udma_glue_release_rx_flow()', simplify it, add some labels and branch > at the correct places when an error is detected. Good catch! > Doing so, we also NULLify 'flow->udma_rflow' in a path that was lacking it. Even better catch ;) > Fixes: d70241913413 ("dmaengine: ti: k3-udma: Add glue layer for non DMAengine user") > Signed-off-by: Christophe JAILLET > --- > Not sure that the last point of the description is correct. Maybe, the > 'xudma_rflow_put / return -ENODEV;' should be kept in order not to > override 'flow->udma_rflow'. > --- > drivers/dma/ti/k3-udma-glue.c | 30 ++++++++++++++++++++---------- > 1 file changed, 20 insertions(+), 10 deletions(-) > > diff --git a/drivers/dma/ti/k3-udma-glue.c b/drivers/dma/ti/k3-udma-glue.c > index dbccdc7c0ed5..890573eb1625 100644 > --- a/drivers/dma/ti/k3-udma-glue.c > +++ b/drivers/dma/ti/k3-udma-glue.c > @@ -578,12 +578,12 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn, > if (IS_ERR(flow->udma_rflow)) { > ret = PTR_ERR(flow->udma_rflow); > dev_err(dev, "UDMAX rflow get err %d\n", ret); > - goto err; > + goto err_return; return err; ? > } Optionally you could have moved the rx_chn->flows_ready++; here and > > if (flow->udma_rflow_id != xudma_rflow_get_id(flow->udma_rflow)) { > - xudma_rflow_put(rx_chn->common.udmax, flow->udma_rflow); > - return -ENODEV; > + ret = -ENODEV; > + goto err_rflow_put; goto err; > } > > /* request and cfg rings */ > @@ -592,7 +592,7 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn, > if (!flow->ringrx) { > ret = -ENODEV; > dev_err(dev, "Failed to get RX ring\n"); > - goto err; > + goto err_rflow_put; > } > > flow->ringrxfdq = k3_ringacc_request_ring(rx_chn->common.ringacc, > @@ -600,19 +600,19 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn, > if (!flow->ringrxfdq) { > ret = -ENODEV; > dev_err(dev, "Failed to get RXFDQ ring\n"); > - goto err; > + goto err_ringrx_free; > } > > ret = k3_ringacc_ring_cfg(flow->ringrx, &flow_cfg->rx_cfg); > if (ret) { > dev_err(dev, "Failed to cfg ringrx %d\n", ret); > - goto err; > + goto err_ringrxfdq_free; > } > > ret = k3_ringacc_ring_cfg(flow->ringrxfdq, &flow_cfg->rxfdq_cfg); > if (ret) { > dev_err(dev, "Failed to cfg ringrxfdq %d\n", ret); > - goto err; > + goto err_ringrxfdq_free; > } > > if (rx_chn->remote) { > @@ -662,7 +662,7 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn, > if (ret) { > dev_err(dev, "flow%d config failed: %d\n", flow->udma_rflow_id, > ret); > - goto err; > + goto err_ringrxfdq_free; > } > > rx_chn->flows_ready++; > @@ -670,8 +670,18 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn, > flow->udma_rflow_id, rx_chn->flows_ready); > > return 0; > -err: > - k3_udma_glue_release_rx_flow(rx_chn, flow_idx); > + > +err_ringrxfdq_free: > + k3_ringacc_ring_free(flow->ringrxfdq); > + > +err_ringrx_free: > + k3_ringacc_ring_free(flow->ringrx); > + > +err_rflow_put: > + xudma_rflow_put(rx_chn->common.udmax, flow->udma_rflow); > + flow->udma_rflow = NULL; > + > +err_return: You could have kept the single err label and just copy the release_rx_flow() without the rx_chn->flows_ready--; I don't have anything against multiple labels as such, but a single one might be easier to follow? and you don't need the err_return, just return in place when you would jump to it. > return ret; > } > > - Péter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki