Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5352822ybi; Wed, 12 Jun 2019 00:47:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKqM3XVdzvxulkPlfhUcPKOHWvo6KGVfx2MPUp4g/ftT7FUTi042ENWZMGzwSSNwdkiSaA X-Received: by 2002:a65:63c3:: with SMTP id n3mr3950854pgv.139.1560325622729; Wed, 12 Jun 2019 00:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560325622; cv=none; d=google.com; s=arc-20160816; b=MAiHx/lS1i2fN2S5pZZGXLZaQliuZV+tG9P7pCYatBCnz7DyvVv6NlhUH+2zpeqorH DELKNw4eMSGnMG6GqIupcjewXzS5DzmaMCgGpSt/zrfNcSPhph9NEacDwd78DHsvNs8D +TiviXP53r5HQk5N2QUYErtoizL+Asipw4feHxzeKsADDlA/yzP9l1Va1xVVZIeeiZT8 5SY1uAZ0bQvEW+R8+SrQCXzNPP0WC0YaYvNwNEI6VtZuGMYAd3jJvOhhkO7N9BsiVIL5 hYvJ8vIqSAMVtcR8auC8O+urN7JJFWczoCKwrrzHThdfyjtwK8cgtnQ1hM33wxpFM8IL kXcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=QdK26CVwWrBNPw+Sk2y20GmQbor5Btpd6Ow3/Jy67bI=; b=OX2PcWwJGJQKwM0MGDJWqRgAkZ8g/FDuBTNmFGx1oB7tZ4T925uhLNjqD/BBJc4v+F j2JpCQms7Iy+QixF+nkGXhyojU4aI3hIo7tWFwnPyl2Q15S118MjN8oENhMl9oaqYZF0 GomUx0yN3Xq+G8Gx0rchrxuPXm+ZP+8UyY6TUuDlH1exTDZTT3r8004zjvH//fYjxLPk JXJPr8RKTkL9kTD4fvqoTJdphTXGIhEnFQANQNKTBORYFMp/8AlJzGUuh2pHDxJU4gpn SzXdf1SqwoFINktl4I3zLNwwmyZQuFtmK3ERu/G6O8UQU2sxqJA0D6UzAHLRtIAASFTz /IYQ== ARC-Authentication-Results: i=1; mx.google.com; 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=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a7si6507475pfc.54.2019.06.12.00.46.43; Wed, 12 Jun 2019 00:47:02 -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; 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=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407603AbfFLDei (ORCPT + 99 others); Tue, 11 Jun 2019 23:34:38 -0400 Received: from inva020.nxp.com ([92.121.34.13]:52528 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404347AbfFLDeh (ORCPT ); Tue, 11 Jun 2019 23:34:37 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A77731A0C2D; Wed, 12 Jun 2019 05:34:35 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 26B1E1A0C1D; Wed, 12 Jun 2019 05:34:31 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 4B33F402CA; Wed, 12 Jun 2019 11:34:25 +0800 (SGT) From: Anson.Huang@nxp.com To: shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, leonard.crestez@nxp.com, viresh.kumar@linaro.org, abel.vesa@nxp.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Linux-imx@nxp.com Subject: [PATCH 1/2] soc: imx8: Fix potential kernel dump in error path Date: Wed, 12 Jun 2019 11:36:19 +0800 Message-Id: <20190612033620.3556-1-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anson Huang When SoC's revision value is 0, SoC driver will print out "unknown" in sysfs's revision node, this "unknown" is a static string which can NOT be freed, this will caused below kernel dump in later error path which calls kfree: kernel BUG at mm/slub.c:3942! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in: CPU: 2 PID: 1 Comm: swapper/0 Not tainted 5.2.0-rc4-next-20190611-00023-g705146c-dirty #2197 Hardware name: NXP i.MX8MQ EVK (DT) pstate: 60000005 (nZCv daif -PAN -UAO) pc : kfree+0x170/0x1b0 lr : imx8_soc_init+0xc0/0xe4 sp : ffff00001003bd10 x29: ffff00001003bd10 x28: ffff00001121e0a0 x27: ffff000011482000 x26: ffff00001117068c x25: ffff00001121e100 x24: ffff000011482000 x23: ffff000010fe2b58 x22: ffff0000111b9ab0 x21: ffff8000bd9dfba0 x20: ffff0000111b9b70 x19: ffff7e000043f880 x18: 0000000000001000 x17: ffff000010d05fa0 x16: ffff0000122e0000 x15: 0140000000000000 x14: 0000000030360000 x13: ffff8000b94b5bb0 x12: 0000000000000038 x11: ffffffffffffffff x10: ffffffffffffffff x9 : 0000000000000003 x8 : ffff8000b9488147 x7 : ffff00001003bc00 x6 : 0000000000000000 x5 : 0000000000000003 x4 : 0000000000000003 x3 : 0000000000000003 x2 : b8793acd604edf00 x1 : ffff7e000043f880 x0 : ffff7e000043f888 Call trace: kfree+0x170/0x1b0 imx8_soc_init+0xc0/0xe4 do_one_initcall+0x58/0x1b8 kernel_init_freeable+0x1cc/0x288 kernel_init+0x10/0x100 ret_from_fork+0x10/0x18 This patch fixes this potential kernel dump when a chip's revision is "unknown", it is done by always printing out the revision value. Fixes: a7e26f356ca1 ("soc: imx: Add generic i.MX8 SoC driver") Signed-off-by: Anson Huang --- drivers/soc/imx/soc-imx8.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/soc/imx/soc-imx8.c b/drivers/soc/imx/soc-imx8.c index 02309a2..86b925a 100644 --- a/drivers/soc/imx/soc-imx8.c +++ b/drivers/soc/imx/soc-imx8.c @@ -96,11 +96,6 @@ static const struct of_device_id imx8_soc_match[] = { { } }; -#define imx8_revision(soc_rev) \ - soc_rev ? \ - kasprintf(GFP_KERNEL, "%d.%d", (soc_rev >> 4) & 0xf, soc_rev & 0xf) : \ - "unknown" - static int __init imx8_soc_init(void) { struct soc_device_attribute *soc_dev_attr; @@ -135,7 +130,10 @@ static int __init imx8_soc_init(void) soc_rev = data->soc_revision(); } - soc_dev_attr->revision = imx8_revision(soc_rev); + soc_dev_attr->revision = kasprintf(GFP_KERNEL, + "%d.%d", + (soc_rev >> 4) & 0xf, + soc_rev & 0xf); if (!soc_dev_attr->revision) { ret = -ENOMEM; goto free_soc; -- 2.7.4