Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp90280ybl; Thu, 9 Jan 2020 17:33:45 -0800 (PST) X-Google-Smtp-Source: APXvYqzZVqg4BhJSfPsoQPMI8SHLOe62ugeUjtvvf/YLCsew0uoUNVGrJaKxiAfYzU27Eutp0WbO X-Received: by 2002:aca:6744:: with SMTP id b4mr321858oiy.99.1578620025864; Thu, 09 Jan 2020 17:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578620025; cv=none; d=google.com; s=arc-20160816; b=QyAmTF7Or4FUTZItIhjm7vPeFVIpRafSb6lJT/EjoLB0q5l/J7Vj4nETPs21XeA9Kd aULB1p/reQ7z2s4ZRJgApX+M+euY6wJoFv/ZI9Q3NITXlovN+2E/cqweLTUup9cJQduL BM3bRueKm53TFNtyAoT4Qf7gNW562cBqLBMa2/t5FHNNAjXJD8TdQy5DZ3T7Ue3NDtm/ mnI6xKaAqfjvbXm23WCLoHDfYaMKu8mJ2FVkmaUFDq+71QJ7SrebuKTeGvzCdu1iQX2P 1V9MjIRT43kadZaXb1gE91aSJPUoDLNbzZoPvWHAd3iqo38BooQLRmf+5h1PtTIUqkNJ Y6sw== 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=nvP/YkB/McjB81sv0U/kkGl4qz6KVPDItZILlhBx86M=; b=gCs5yi026ZLDwAiThA/NDKdt3CEjwfGOIwsittz3zE/NQhknjgS+rejRqHGCxE0Hln rmLGp5lCF1dqPgQF1Ji1qSz2OaaM7u57HjPZwkMGlYV/x67/znwZ4/g8oT4eH2jhhFfq OBoY1tJ/ZwATbIPMhMThhO/kgVx2WnYJVuwZCurJAb1VrtEkUfpaczGl9WT+dzKQbq7N 7FnF0NaEWODFD+8kh70+a470Ly7cs926nVJfhzu4b25is+Xh5aOt53tmNQAP/rCWQujI o3vDrFkqfFs4FMox69TeOzZyM+eFgTR71TXLZCojTs5KqsuZf2d1rCbONvIfVG8LEAeu uHCA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s13si181692otd.186.2020.01.09.17.33.33; Thu, 09 Jan 2020 17:33:45 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730662AbgAJBbE (ORCPT + 99 others); Thu, 9 Jan 2020 20:31:04 -0500 Received: from mail.loongson.cn ([114.242.206.163]:57308 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730593AbgAJBbE (ORCPT ); Thu, 9 Jan 2020 20:31:04 -0500 Received: from linux.localdomain (unknown [123.138.236.242]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx32vH0xde7cgCAA--.0S2; Fri, 10 Jan 2020 09:30:48 +0800 (CST) From: Tiezhu Yang To: Paul Burton , Ralf Baechle , Huacai Chen , Jiaxun Yang Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() Date: Fri, 10 Jan 2020 09:30:42 +0800 Message-Id: <1578619842-926-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dx32vH0xde7cgCAA--.0S2 X-Coremail-Antispam: 1UD129KBjvdXoWrtry3GFyfKFWfGF1kuFWxWFg_yoWfXFbEgF WIyF4kGry8Jwn7X3yj9r13WrWfWa4DCF43CFnxW34Igas0qrn8JrW8Ar4UAF47XrWjyrW5 Z3ykCFyfCa1fGjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb28YjsxI4VWDJwAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I 6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM2 8CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0 cI8IcVCY1x0267AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I 8E87Iv6xkF7I0E14v26r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xv F2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r 4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY02Avz4vE14v_KwCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6Fyj6rWUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j00PfUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If kzalloc fails, it should return -ENOMEM, otherwise may trigger a NULL pointer dereference. Fixes: 3adeb2566b9b ("MIPS: Loongson: Improve LEFI firmware interface") Signed-off-by: Tiezhu Yang --- arch/mips/loongson64/platform.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/mips/loongson64/platform.c b/arch/mips/loongson64/platform.c index 13f3404..9674ae1 100644 --- a/arch/mips/loongson64/platform.c +++ b/arch/mips/loongson64/platform.c @@ -27,6 +27,9 @@ static int __init loongson3_platform_init(void) continue; pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL); + if (!pdev) + return -ENOMEM; + pdev->name = loongson_sysconf.sensors[i].name; pdev->id = loongson_sysconf.sensors[i].id; pdev->dev.platform_data = &loongson_sysconf.sensors[i]; -- 2.1.0