Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8097FC3DA7D for ; Tue, 3 Jan 2023 17:58:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E120785477; Tue, 3 Jan 2023 18:58:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1672768700; bh=X+JP7UIgc7JV+VffqM1IaXV5peUb2iEMVPwZEBTJ54I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oAbIy1J0RRV04ZgG9REdd0+5zUMlksVAuB6M5Io2j/Vg1Ue4ixkZn/I5buUI5lQtE 4mQ/FiLn/1pLvIYFVHd6hFIk7iH0YPhpfz5+7EmyPi06o7Yx7o2v9du7N6t4xIf9Qe 7KzhCzOxLi6TeDt5zo9MFskLqBCP4lTF0rt5gzU4BSgKmfP2ApqysuUULeZ147MODt vciknIW4ZwaZ1ixH1H6BwN2H/f+2y8TJdzHmP7J4oi0yEQvmx1FiaZk9h0RfD8fIxQ 7NZdqj+uL6KMPqgYCXca3Jqaw8IQ68wNqkdY9OJ3SUfXM/jBqELZLdodSDqFYrC9kX o8j/Q4jEeOzWA== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 2D8EF84231; Tue, 3 Jan 2023 18:58:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1672768697; bh=X+JP7UIgc7JV+VffqM1IaXV5peUb2iEMVPwZEBTJ54I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=k8pL6YjF8rB773gYYwVF8tcd+7ex666q2d9dNISkb6feQk57qxeveRxI59Su7MrGM UrkBCkjo2FUMi1XF1eAOP21drcCkRTxrPDUQLCO1ZSONtBz6ax44J4buKFarMkeGAL vUwxj3Yv2RbzUivIAC8VhOTsyf/pmdjJp0kirlDU9u/4oa33Q4HR+2O/yuESCd7lTX 7DGCXepoT0j1uJx9giIkX+lohkxzQP4c1f7STuspdl2BcvRmBUSqBQfd+SvHfWGMD+ wron7rJWoq7kWLu6ht4vEaM7oph6ZqFS7MkibvIrTGFxek2+hZ2ygVqTApbfpcOo+/ 0a9QK3m665QPQ== Message-ID: Date: Tue, 3 Jan 2023 18:58:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v2 1/3] phy: at91: Add support for the USB 2.0 PHY's of SAMA7 Content-Language: en-US To: Sergiu.Moga@microchip.com, weijie.gao@mediatek.com, sumit.garg@linaro.org, michal.simek@amd.com, jim.t90615@gmail.com, sjg@chromium.org, aford173@gmail.com, judge.packham@gmail.com, lukma@denx.de, sr@denx.de, samuel@sholland.org Cc: u-boot@lists.denx.de, Mihai.Sain@microchip.com References: <20230103143040.87045-1-sergiu.moga@microchip.com> <20230103143040.87045-2-sergiu.moga@microchip.com> <5db7ed4d-74bf-777d-3907-df9e72eb8b94@denx.de> <37ef9722-c69a-00a3-2cdf-62f7ff698f2a@microchip.com> From: Marek Vasut In-Reply-To: <37ef9722-c69a-00a3-2cdf-62f7ff698f2a@microchip.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 1/3/23 17:54, Sergiu.Moga@microchip.com wrote: > On 03.01.2023 17:31, Marek Vasut wrote: >> On 1/3/23 15:30, Sergiu Moga wrote: >>> In order to have USB functionality, drivers for SAMA7's >>> USB 2.0 PHY's have been added. There is one driver >>> for UTMI clock's SFR and RESET required functionalities and >>> one for its three possible subclocks of the phy's themselves. >>> In order for this layout to properly work in conjunction with >>> CCF and DT, the former driver will also act as a clock provider >>> for the three phy's with the help of a custom hook into the >>> driver's of_xlate method. >> >> [...] >> >>> +static int sama7_utmi_probe(struct udevice *dev) >>> +{ >>> +     struct clk *utmi_parent_clk, *utmi_clk; >>> +     struct regmap *regmap_sfr; >>> +     struct reset_ctl *phy_reset; >>> +     int i; >>> +     char name[16]; >>> + >>> +     utmi_parent_clk = devm_clk_get(dev, "utmi_clk"); >>> +     if (IS_ERR(utmi_parent_clk)) >>> +             return PTR_ERR(utmi_parent_clk); >>> + >>> +     regmap_sfr = syscon_regmap_lookup_by_phandle(dev, "sfr-phandle"); >>> +     if (IS_ERR(regmap_sfr)) >>> +             return PTR_ERR(regmap_sfr); >>> + >>> +     for (i = 0; i < ARRAY_SIZE(sama7_utmick); i++) { >>> +             snprintf(name, sizeof(name), "usb%d_reset", i); >>> +             phy_reset = devm_reset_control_get(dev, name); >>> +             if (IS_ERR(phy_reset)) >>> +                     return PTR_ERR(phy_reset); >>> + >>> +             utmi_clk = sama7_utmi_clk_register(regmap_sfr, phy_reset, >>> +                                                sama7_utmick[i].n, >>> +                                                sama7_utmick[i].p, >>> +                                                sama7_utmick[i].id); >>> +             if (IS_ERR(utmi_clk)) >>> +                     return PTR_ERR(utmi_clk); >> >> Isn't this going to leak memory if i>0 and a failure occurs ? I think it >> will, since sama7_utmi_clk_register() calls kzalloc() . > > Yes, you are right. Perhaps something like this should work better > instead, wouldn't you agree? > > static int sama7_utmi_probe(struct udevice *dev) > { > - struct clk *utmi_parent_clk, *utmi_clk; > + struct clk *utmi_parent_clk, *utmi_clk[ARRAY_SIZE(sama7_utmick)]; > + struct sama7_utmi_clk *uclk; > struct regmap *regmap_sfr; > struct reset_ctl *phy_reset; > - int i; > + int i, j; > char name[16]; > > utmi_parent_clk = devm_clk_get(dev, "utmi_clk"); > @@ -153,12 +154,18 @@ static int sama7_utmi_probe(struct udevice *dev) > if (IS_ERR(phy_reset)) > return PTR_ERR(phy_reset); > > - utmi_clk = sama7_utmi_clk_register(regmap_sfr, phy_reset, > + utmi_clk[i] = sama7_utmi_clk_register(regmap_sfr, phy_reset, > sama7_utmick[i].n, > sama7_utmick[i].p, > sama7_utmick[i].id); > - if (IS_ERR(utmi_clk)) > + if (IS_ERR(utmi_clk)) { > + for (j = 0; j < i; j++) { > + uclk = to_sama7_utmi_clk(utmi_clk[j]); > + kfree(uclk); Do the usual error handling path using goto: { ... if (IS_ERR(...)) goto error_clk_register; ... error_clk_register: kfree(); error_something_else: clean_up_other_stuff(); return ret; }