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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35C31C6FD1D for ; Fri, 17 Mar 2023 14:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231176AbjCQODw (ORCPT ); Fri, 17 Mar 2023 10:03:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbjCQODr (ORCPT ); Fri, 17 Mar 2023 10:03:47 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BB0275A58; Fri, 17 Mar 2023 07:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=E7Js/gL7fDNHxFoBAEe3ebsc95WWzM8qRUyoE8r02HY=; b=QbIEd+2HuYWiLs46y1jPNOgTcp LTHARoM7vQyJ2bdFSQi9JuIevpg4w5wMt7Edz4Usm6KyqHgHu0Mjc/GI/SgVL+pSUVgOHo4KKUuBP p2aJ2TkU+oZLtWtkIUOBkP2HiaLNb6FUvmA8duuYk+YuU9kCF3BJAjxus4dV2+ooJUdQ=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pdAg8-007cC5-OJ; Fri, 17 Mar 2023 15:03:32 +0100 Date: Fri, 17 Mar 2023 15:03:32 +0100 From: Andrew Lunn To: Michal Kubiak Cc: Christian Marangi , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Heiner Kallweit , Russell King , Gregory Clement , Sebastian Hesselbarth , Andy Gross , Bjorn Andersson , Konrad Dybcio , John Crispin , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lee Jones , linux-leds@vger.kernel.org Subject: Re: [net-next PATCH v4 04/14] net: phy: Add a binding for PHY LEDs Message-ID: References: <20230317023125.486-1-ansuelsmth@gmail.com> <20230317023125.486-5-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 17, 2023 at 02:38:15PM +0100, Michal Kubiak wrote: > On Fri, Mar 17, 2023 at 03:31:15AM +0100, Christian Marangi wrote: > > From: Andrew Lunn > > > > Define common binding parsing for all PHY drivers with LEDs using > > phylib. Parse the DT as part of the phy_probe and add LEDs to the > > linux LED class infrastructure. For the moment, provide a dummy > > brightness function, which will later be replaced with a call into the > > PHY driver. > > > > Hi Andrew, > > Personally, I see no good reason to provide a dummy implementation > of "phy_led_set_brightness", especially if you implement it in the next > patch. You only use that function only the function pointer in > "led_classdev". I think you can just skip it in this patch. Hi Michal The basic code for this patch has been sitting in my tree for a long time. It used to be, if you did not have a set_brightness method in cdev, the registration failed. That made it hard to test this patch on its own during development work, did i have the link list correct, can i unload the PHY driver without it exploding etc. I need to check if it is still mandatory. > > +static int of_phy_led(struct phy_device *phydev, > > + struct device_node *led) > > +{ > > + struct device *dev = &phydev->mdio.dev; > > + struct led_init_data init_data = {}; > > + struct led_classdev *cdev; > > + struct phy_led *phyled; > > + int err; > > + > > + phyled = devm_kzalloc(dev, sizeof(*phyled), GFP_KERNEL); > > + if (!phyled) > > + return -ENOMEM; > > + > > + cdev = &phyled->led_cdev; > > + > > + err = of_property_read_u32(led, "reg", &phyled->index); > > + if (err) > > + return err; > > Memory leak. 'phyled' is not freed in case of error. devm_ API, so it gets freed when the probe fails. > > + > > + cdev->brightness_set_blocking = phy_led_set_brightness; > > Please move this initialization to the patch where you are actually > implementing this callback. > > > + cdev->max_brightness = 1; > > + init_data.devicename = dev_name(&phydev->mdio.dev); > > + init_data.fwnode = of_fwnode_handle(led); > > + > > + err = devm_led_classdev_register_ext(dev, cdev, &init_data); > > + if (err) > > + return err; > > Another memory leak. Ah, maybe you don't know about devm_ ? devm_ allocations and actions register an action to be taken when the device is removed, either because the probe failed, or when the device is unregistered. For memory allocation, the memory is freed automagically. For actions like registering an LED, requesting an interrupt etc, an unregister/release is performed. This makes cleanup less buggy since the core does it. Andrew