Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4374843imw; Tue, 12 Jul 2022 06:59:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uCBBuGvDK3fbTzOWECyky1hszZzoVfzSWU12TJ1o7BskF2kwrkWdM0sdrXm+Yo3g9MT1ap X-Received: by 2002:a17:907:2722:b0:72b:6d79:1a46 with SMTP id d2-20020a170907272200b0072b6d791a46mr6769430ejl.713.1657634388480; Tue, 12 Jul 2022 06:59:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657634388; cv=none; d=google.com; s=arc-20160816; b=Ew36eN0sE1olWq2XuE7hK12ND2aSN8nt3YQyaEWW1CohzyX0fsykiHDXDl7PtstgSk 2j3fYK+Thl2ztRaJPInyd0IEVmZQ1wBhg0dP4H/nRlpmrQ/Ka8NZjEt6knATTIZUQuKO ZLIBbL14zsoneeoJJ6Lv14NA9mXc3g3SBoFjax+b6k17tvlpNeB4fxI/DkQg2zsKkdVR 8N8oBVLfEyFbm3T/puTa0A316ojesRCxawkXoCo4eirdDuDz1sIgLy7Z5LpTG7aLzVWV 5cKUSPR6lPD7SI/Hgam9tmFjwF0jcjRr3VEfNMatTKazbskK6kpAL9oaGZLOF0mRb9SU XuVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=c/sYXMoiNTcLP4oKia5QR42veWinE4cNjWYJuUyBSyg=; b=mr4ToOuKQZKAHZmbp0zoS12H0fWjzIOmen7dvch71IYIoQV4xYNfFe5yfOvzDkkfSM 8OwJX8VgjFicbku1zUh52Ri2vYwag6/GG0z74DuPmdywdHQIF+87w7LGVZNCE4SWv4wV 0hjW0vR+9NgQp924eg4qLTD4UhSmsNXlRhVzQc/rQGJQT6za233XLVxovuMrMDNbur1D sl+BqGn3mH/Zd2dHtsuCXMPLJi90VDFvfWQa8NuJVOgJ1+7W+UZsYc7ZiIJutz7byfbq 8+uEbUMNFSc7EvUscoNfKfQ9aYnvMH72mUJF7WPUFVu+Wddgc6NrBOaKAmgYHtE1uV4f y+6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=A0HZ3XRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a05640211cd00b0043a0ca47337si18450776edw.185.2022.07.12.06.59.22; Tue, 12 Jul 2022 06:59:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=A0HZ3XRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232706AbiGLNaZ (ORCPT + 99 others); Tue, 12 Jul 2022 09:30:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232937AbiGLNaO (ORCPT ); Tue, 12 Jul 2022 09:30:14 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D121BB6289 for ; Tue, 12 Jul 2022 06:30:07 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id l22-20020a05600c4f1600b003a2e10c8cdeso776142wmq.1 for ; Tue, 12 Jul 2022 06:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c/sYXMoiNTcLP4oKia5QR42veWinE4cNjWYJuUyBSyg=; b=A0HZ3XRjr20kgR1tWrM1jW4cvR2su5kDxMBHTSH67PN2hoL56wN/CnYJXUFc8GHaDu 7ASpMkJfV9Lc/ylHpcVrju+tH7J3uPDWYhRv8KrEQPbyW7dPWYouM1EhxWOtG45W/+8O CaLQm7S3ItQjOLfUts32q9xTtEOVfEPcDbk/C1sQDNOj8NzmDTlc/l5naxoqPWFUtzSc bSrp1iq/8tyaWpAv2dRwhY3xA87xtgx45LVWvAl6WrCR90C+/OQ/yAHgPj/hyOW/jjrq 0OA46fBk/pA5xaU2BhGQNcuzHmVvWVTf1VYBVjJx/vW0GQuZhGgIRXA95sp/y2A+cZaf ndRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c/sYXMoiNTcLP4oKia5QR42veWinE4cNjWYJuUyBSyg=; b=3MJMsIAiLz+pTE6rTXZtUGJhSy9kK47RyKIkJFo7zbxi59PoLFajFYfdQRu/RTapda ejNoa6oygfJQbWMl45KyeckbBQz3c+qx9PHX/PmM3WD/4qGb0H5Lr4gR7r/4Ds9Rsnr+ 2RpWtLFj6vVplhH3NYsYSQXE4j6e9p+m+eGMVCoXj66WD/f6tYoRLDCfOKTovRI8dgvq mTicj2EineszpFXTDpAPObjqavgNAMgRnh2gE1ibT/ZGlDKP1NqEMuo2ZZwEbc7wOUPj AEuJksThlJRTq2rPYPtUgXA4I2ae7ptxe6rjRNNyebeB3pD9zn+nN9jdMHWpdpvSEjFC 3nIw== X-Gm-Message-State: AJIora9cmTS6KjBdiolAkf1ug9l1MZampXmc4l8VUGXJis2U/eRHXbPI qmArJ+YHXvTdQaArz8OJ73hErrzAJgnGrWmE8hL6iQ== X-Received: by 2002:a05:600c:4fc8:b0:3a1:99cf:800 with SMTP id o8-20020a05600c4fc800b003a199cf0800mr3853176wmq.60.1657632606217; Tue, 12 Jul 2022 06:30:06 -0700 (PDT) MIME-Version: 1.0 References: <202207101328.ASjx88yj-lkp@intel.com> In-Reply-To: <202207101328.ASjx88yj-lkp@intel.com> From: David Gow Date: Tue, 12 Jul 2022 21:29:55 +0800 Message-ID: Subject: Re: [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy' To: Dan Carpenter Cc: kbuild@lists.01.org, Daniel Latypov , kernel test robot , kbuild-all@lists.01.org, "GNU/Weeb Mailing List" , Linux Kernel Mailing List , Shuah Khan , Brendan Higgins Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 12, 2022 at 8:51 PM Dan Carpenter wrote: > > tree: https://github.com/ammarfaizi2/linux-block shuah/linux-kselftest/kunit > head: 7635778bac7e46458392c1261e3916e8e9e86860 > commit: d2fbdde838f270377de4fc20e919aac3941ea55f [4/16] kunit: use kmemdup in kunit_filter_tests(), take suite as const > config: arc-randconfig-m031-20220707 (https://download.01.org/0day-ci/archive/20220710/202207101328.ASjx88yj-lkp@intel.com/config) > compiler: arc-elf-gcc (GCC) 11.3.0 > > If you fix the issue, kindly add following tag where applicable > Reported-by: kernel test robot > Reported-by: Dan Carpenter > > smatch warnings: > lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy' > > vim +/copy +78 lib/kunit/executor.c Thanks: clang-analyzer also picked this up here: https://lore.kernel.org/all/c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com/ (... snip ...) > a127b154a8f2317 Daniel Latypov 2021-09-14 76 filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL); > a02353f491622e4 Daniel Latypov 2022-05-11 77 if (!filtered) > a02353f491622e4 Daniel Latypov 2022-05-11 @78 return ERR_PTR(-ENOMEM); > > kfree(copy)? Is the burden of random devs looking at this warning > forever more than the burden of adding a kfree()? Hard to measure. > I mean, it's the burden of not only adding a kfree(), but also a couple of {}s. :-) Regardless, this patch should add them: https://lore.kernel.org/linux-kselftest/20220712095627.1770312-1-davidgow@google.com/ > a127b154a8f2317 Daniel Latypov 2021-09-14 79 > a127b154a8f2317 Daniel Latypov 2021-09-14 80 n = 0; > a127b154a8f2317 Daniel Latypov 2021-09-14 81 kunit_suite_for_each_test_case(suite, test_case) { > a127b154a8f2317 Daniel Latypov 2021-09-14 82 if (!test_glob || glob_match(test_glob, test_case->name)) > a127b154a8f2317 Daniel Latypov 2021-09-14 83 filtered[n++] = *test_case; > a127b154a8f2317 Daniel Latypov 2021-09-14 84 } > a127b154a8f2317 Daniel Latypov 2021-09-14 85 > a127b154a8f2317 Daniel Latypov 2021-09-14 86 copy->test_cases = filtered; > a127b154a8f2317 Daniel Latypov 2021-09-14 87 return copy; > a127b154a8f2317 Daniel Latypov 2021-09-14 88 } > Cheers, -- David