From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1C52C47E4B for ; Thu, 15 Jul 2021 09:21:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAF9660041 for ; Thu, 15 Jul 2021 09:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237459AbhGOJYm (ORCPT ); Thu, 15 Jul 2021 05:24:42 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:11314 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbhGOJYj (ORCPT ); Thu, 15 Jul 2021 05:24:39 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GQTKR3PH3z7tf4; Thu, 15 Jul 2021 17:17:15 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 15 Jul 2021 17:21:40 +0800 Received: from [10.174.179.0] (10.174.179.0) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 15 Jul 2021 17:21:39 +0800 Subject: Re: [PATCH 1/1] stm class: dummy_stm: Fix error return code in dummy_stm_init() To: Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , Greg Kroah-Hartman , linux-stm32 , linux-arm-kernel , linux-kernel References: <20210508023615.1827-1-thunder.leizhen@huawei.com> From: "Leizhen (ThunderTown)" Message-ID: Date: Thu, 15 Jul 2021 17:21:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20210508023615.1827-1-thunder.leizhen@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.0] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all: Can someone review it? Although it is unlikely that the OOM will occur during initialization, this is indeed a coding error. On 2021/5/8 10:36, Zhen Lei wrote: > Although 'ret' has been initialized to -ENOMEM, but it will be reassigned > by the "ret = stm_register_device(...)" statement in the for loop. So > that, the value of 'ret' is unknown when kasprintf() failed. > > Fixes: bcfdf8afdebe ("stm class: dummy_stm: Create multiple devices") > Reported-by: Hulk Robot > Signed-off-by: Zhen Lei > --- > drivers/hwtracing/stm/dummy_stm.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/hwtracing/stm/dummy_stm.c b/drivers/hwtracing/stm/dummy_stm.c > index 38528ffdc0b3..36d32e7afb35 100644 > --- a/drivers/hwtracing/stm/dummy_stm.c > +++ b/drivers/hwtracing/stm/dummy_stm.c > @@ -68,7 +68,7 @@ static int dummy_stm_link(struct stm_data *data, unsigned int master, > > static int dummy_stm_init(void) > { > - int i, ret = -ENOMEM; > + int i, ret; > > if (nr_dummies < 0 || nr_dummies > DUMMY_STM_MAX) > return -EINVAL; > @@ -80,8 +80,10 @@ static int dummy_stm_init(void) > > for (i = 0; i < nr_dummies; i++) { > dummy_stm[i].name = kasprintf(GFP_KERNEL, "dummy_stm.%d", i); > - if (!dummy_stm[i].name) > + if (!dummy_stm[i].name) { > + ret = -ENOMEM; > goto fail_unregister; > + } > > dummy_stm[i].sw_start = master_min; > dummy_stm[i].sw_end = master_max; >