Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1510972ybm; Thu, 23 May 2019 02:13:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7MOcNoaCBtzIEMDGbvTy0QDzr08twp3QUxpcdk0Xhz3NDB/ry7qwgdTFrcwx1qUVuorFE X-Received: by 2002:a17:902:7591:: with SMTP id j17mr36398295pll.200.1558602805559; Thu, 23 May 2019 02:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558602805; cv=none; d=google.com; s=arc-20160816; b=rbjUe1DtP2V4hXcBRj8K4m0KmCcJTq3G9AI6/7oprpwNVoiEaT7Nxdsh+nS6u5j7h2 6yYY8UX1lzukuC73INsqyfPPt0jUAmsP5GEV1Hk4A2YtQtxxEtSPyCW/Jh15KT5YPEYr 7PAeYnxKQ60WI3IMFYNlMSBBabffbJnLz751xVjU7PxyX/qrDzElm4BHTisViO/NQyby ywdU77/TYEsf5b/zdN/21Q8A8QhSSqlBs1YFqHlGG/vpsW4Gj+79zHicHPh+Erdq9rGl mbkNVWQDY/hgH63dHrArhOT5qTrnK5ULkM2XbD9xd391eF3Ft1B2f58pzt52+rUuBXzV xwuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gvMc8e1blxSFjrQAJfdsPT3oO6xm8lpzhMKEL0P1bLs=; b=XJDtV5HmLgt7ldkLrAQv9Voc5H6kltano5AffQf0TlStuQbxll+9ShafN+Od9cA1of RCIaYXSBu9PxHS7PpeBJUckebhZc2A0A1Z5VNCE6Ir5EpTCYzSWn0Fk1pyXSjMZUiPVD 03qi5bHSxAr3y9uQg2b/nan6yyrGYbKtDwD9g1dyDe3p/X5Wquqj+mvkfBudB8EgN2ak BaJyTZv/VP5lqJNf9P5wTYS0BssxEDnbcF7kB5PpFKYIOWvVYte5Wdm9WzK/VXDjdIdd sigOcNXh8+ekcM6ddm/FPv+9lKajlrW9TRrVP4CN4kq0p1GdtXSC8HlAForgpW51+ngk 7Gzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=BQAIxqLQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si28356612pgd.325.2019.05.23.02.13.10; Thu, 23 May 2019 02:13:25 -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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=BQAIxqLQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730103AbfEWJKX (ORCPT + 99 others); Thu, 23 May 2019 05:10:23 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:39022 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727319AbfEWJKW (ORCPT ); Thu, 23 May 2019 05:10:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gvMc8e1blxSFjrQAJfdsPT3oO6xm8lpzhMKEL0P1bLs=; b=BQAIxqLQooHeCeK5WVsEqQJZK kU0lC15VHB4iOLCjEo0UuhKfX4y3viK6OP2dG0YQ9oOblQk2b4q3HSwNPIMmny14TRWG4UCozKlA5 LSeXNBB/Cx6oiH5VNEEfnZAY/pKVf0akXlbK3NNsibQl2F/PxFqGh/k4so0wtQH01qhLM1Fbq75Ne YKz05O5L1cM3FGJVNtTd0z8KF/MEl/sHFwI0BNvvLltd0H58QCZ9AjfNFLqy7MuRGwJdTx2ONuCFP WONoC+lPgkCDImHd509WqDqdqe4Yw1v/jnV0G0nl6/IYVwSU4Mq57bogLMImeNpQCiBDUfMUt+oha dwaTv+zrQ==; Received: from shell.armlinux.org.uk ([2002:4e20:1eda:1:5054:ff:fe00:4ec]:38254) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hTjjQ-0004gL-Ex; Thu, 23 May 2019 10:09:48 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.89) (envelope-from ) id 1hTjjK-0007V5-1i; Thu, 23 May 2019 10:09:42 +0100 Date: Thu, 23 May 2019 10:09:41 +0100 From: Russell King - ARM Linux admin To: Anson Huang Cc: "catalin.marinas@arm.com" , "will.deacon@arm.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "maxime.ripard@bootlin.com" , "olof@lixom.net" , "agross@kernel.org" , "jagan@amarulasolutions.com" , "bjorn.andersson@linaro.org" , Leonard Crestez , "dinguyen@kernel.org" , "enric.balletbo@collabora.com" , Aisheng Dong , Abel Vesa , "l.stach@pengutronix.de" , "tglx@linutronix.de" , "robh@kernel.org" , "gregkh@linuxfoundation.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx Subject: Re: [PATCH V6 1/2] soc: imx: Add SCU SoC info driver support Message-ID: <20190523090941.zd4rbvcimgit5lq5@shell.armlinux.org.uk> References: <1558586911-29309-1-git-send-email-Anson.Huang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1558586911-29309-1-git-send-email-Anson.Huang@nxp.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 04:53:46AM +0000, Anson Huang wrote: > Add i.MX SCU SoC info driver to support i.MX8QXP SoC, introduce > driver dependency into Kconfig as CONFIG_IMX_SCU must be > selected to support i.MX SCU SoC driver, also need to use > platform driver model to make sure IMX_SCU driver is probed > before i.MX SCU SoC driver. This seems buggy... > +static int imx_scu_soc_probe(struct platform_device *pdev) > +{ > + struct soc_device_attribute *soc_dev_attr; > + struct soc_device *soc_dev; > + u32 id, val; > + int ret; > + > + ret = imx_scu_get_handle(&soc_ipc_handle); > + if (ret) > + return ret; > + > + soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), > + GFP_KERNEL); > + if (!soc_dev_attr) > + return -ENOMEM; > + > + soc_dev_attr->family = "Freescale i.MX"; > + > + ret = of_property_read_string(of_root, > + "model", > + &soc_dev_attr->machine); > + if (ret) > + return ret; > + > + id = imx_scu_soc_id(); > + > + /* format soc_id value passed from SCU firmware */ > + val = id & 0x1f; > + soc_dev_attr->soc_id = val ? kasprintf(GFP_KERNEL, "0x%x", val) > + : "unknown"; soc_id can either be an allocated string, or it can be a static string of "unknown". > + if (!soc_dev_attr->soc_id) > + return -ENOMEM; > + > + /* format revision value passed from SCU firmware */ > + val = (id >> 5) & 0xf; > + val = (((val >> 2) + 1) << 4) | (val & 0x3); > + soc_dev_attr->revision = val ? kasprintf(GFP_KERNEL, > + "%d.%d", > + (val >> 4) & 0xf, > + val & 0xf) : "unknown"; revision here is the same. > + if (!soc_dev_attr->revision) { > + ret = -ENOMEM; > + goto free_soc_id; > + } > + > + soc_dev = soc_device_register(soc_dev_attr); > + if (IS_ERR(soc_dev)) { > + ret = PTR_ERR(soc_dev); > + goto free_revision; > + } > + > + return 0; > + > +free_revision: > + kfree(soc_dev_attr->revision); > +free_soc_id: > + kfree(soc_dev_attr->soc_id); Yet here you blindly kfree(), which means you could be doing in effect kfree("unknown") - which will likely result in a kernel oops. Either always make revision/soc_id an allocated string, or use some static storage for the strings (they're only small, static storage is likely to be much more efficient in this case, and there can only be one of these in any case.) > + return ret; > +} > + > +static struct platform_driver imx_scu_soc_driver = { > + .driver = { > + .name = IMX_SCU_SOC_DRIVER_NAME, > + }, > + .probe = imx_scu_soc_probe, > +}; > + > +static int __init imx_scu_soc_init(void) > +{ > + struct platform_device *imx_scu_soc_pdev; > + struct device_node *np; > + int ret; > + > + np = of_find_compatible_node(NULL, NULL, "fsl,imx-scu"); > + if (!np) > + return -ENODEV; > + > + of_node_put(np); > + > + ret = platform_driver_register(&imx_scu_soc_driver); > + if (ret) > + return ret; > + > + imx_scu_soc_pdev = > + platform_device_register_simple(IMX_SCU_SOC_DRIVER_NAME, > + -1, > + NULL, > + 0); > + if (IS_ERR(imx_scu_soc_pdev)) > + platform_driver_unregister(&imx_scu_soc_driver); > + > + return PTR_ERR_OR_ZERO(imx_scu_soc_pdev); > +} > +device_initcall(imx_scu_soc_init); > -- > 2.7.4 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up