Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3378382rdh; Thu, 28 Sep 2023 09:52:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsIrOvzhlKs6/20W2umWBuk7SfLZZyUacyOwg8/t0j+GsAEILn/K6+x8ff9fiKDdG5J5BX X-Received: by 2002:a05:6a20:158b:b0:142:aced:c643 with SMTP id h11-20020a056a20158b00b00142acedc643mr1846786pzj.31.1695919941349; Thu, 28 Sep 2023 09:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695919941; cv=none; d=google.com; s=arc-20160816; b=tAVg7nJGOEFsqSP4CU9xX1wEkWrN+x87YKCZrpId8jEBac4/dBcXYWBrkylsuPMKYg /rTZ22CNvnlvbu9gaPM1oyosaKJ9inEPh8qEgaRbJp/Twbkt+ojGkWog9HE9Frjx6sbK sz0mXWa/wwZiRfdh5RNkWS1FfnAqSueesBXoXjZ2PhSiAuGbPIM1MOWL5YiphLTPtKzR 1s7dEh1JcntnHFy6o4puOypYjdOqz3oUgQiuCIm8kSJRr45odxTvD1sD8QZD/T8t8OgW ibPGaqxOYJEBiz2fUH7e5xSk3YdQVHI7bDG+T6sqQ5Sm5u8z/D40rtYlA/hKLfm6YH7D +OTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9sJHJNvpeHCSQtuFmI1rXyyT6mj/StcEuPaBnCXdF3I=; fh=jtkMVljxaSSnm+wRWxFZHf/UR4p8LFQ8rZaEaUeBMWE=; b=t7awtagItefuyJBAr9Q0iLO500uwx2pxkk/5z2T+kpjbAurpe2HyucG5f7i7BGjHer /LmB+mb2YjQCbiutB7rSxzdd3jLtZQdsKFKLve21Ow7gt3F3MzC5BtRIwPOhGAELfgKP 3ftXD9Ui0pExmGSjrZM/BZgyLaxcrzc5BqO6mxlJGUw2pz7ErANdCK5M6Yiy31w0R5YV tUUQkzHykCu1bmBHf2h4rFa2m8Ko8pF2BFa4xfAfQYbu0bPIVypxOEGJn4MTNMtu2mb+ JqGmAus/YUHnG6Lns+N5csSmythN+Sytl2XEsQwtcnZOw4XUwE68cuQUt0LKaZu1RXqH zH9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=fao53BD6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id n10-20020a17090ade8a00b0026803b4ddfcsi10799792pjv.103.2023.09.28.09.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 09:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=fao53BD6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 97C2280D1EFE; Thu, 28 Sep 2023 03:22:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbjI1KWr (ORCPT + 99 others); Thu, 28 Sep 2023 06:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjI1KWq (ORCPT ); Thu, 28 Sep 2023 06:22:46 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB9EB126; Thu, 28 Sep 2023 03:22:44 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38S80lYA010994; Thu, 28 Sep 2023 05:22:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=PODMain02222019; bh=9 sJHJNvpeHCSQtuFmI1rXyyT6mj/StcEuPaBnCXdF3I=; b=fao53BD6QBhib8sGf WFHc4DS+atw/TqawFdnjaADQ69YcWZvlpdjSZZXuxwzLo2H1/FuzDNqL4sx/FWkv 3iGvKUcHzuaGKY8N11levDzrqdE5gqRyN90TprjQpBC59FkQjZDUB56hb+Vn56Ni oOvcc9Fq8ICCY2uJE288vjI82eUYa82+0/HzImpXj0u9oAz5Jtu/Z63I99EYyvS9 PXn+MHRzE+w9xR8H/Wzm3CQExxrlPU3jvE8ASz+CmYfg9NAlQUeKBpYcWSChBQjB yf9hThXeRI1lP530GytUE9AJbe7SUpDgWSQyzEqRtyGLTvQ33XwmogYhDSsX1xAo B1bEw== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3t9wdxqa1v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 05:22:26 -0500 (CDT) Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Thu, 28 Sep 2023 11:22:24 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.37 via Frontend Transport; Thu, 28 Sep 2023 11:22:24 +0100 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.13]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 6B5A011AB; Thu, 28 Sep 2023 10:22:24 +0000 (UTC) From: Richard Fitzgerald To: , , CC: , , , , "Richard Fitzgerald" Subject: [PATCH] kunit: string-stream: Allow ERR_PTR to be passed to string_stream_destroy() Date: Thu, 28 Sep 2023 11:22:24 +0100 Message-ID: <20230928102224.3842035-1-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: LW8dCchv8JxjJrq8mlPiw3Vo5SDVwOfl X-Proofpoint-GUID: LW8dCchv8JxjJrq8mlPiw3Vo5SDVwOfl X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 03:22:51 -0700 (PDT) Check the stream pointer passed to string_stream_destroy() for IS_ERR_OR_NULL() instead of only NULL. Whatever alloc_string_stream() returns should be safe to pass to string_stream_destroy(), and that will be an ERR_PTR. It's obviously good practise and generally helpful to also check for NULL pointers so that client cleanup code can call string_stream_destroy() unconditionally - which could include pointers that have never been set to anything and so are NULL. Signed-off-by: Richard Fitzgerald --- lib/kunit/string-stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kunit/string-stream.c b/lib/kunit/string-stream.c index a6f3616c2048..54f4fdcbfac8 100644 --- a/lib/kunit/string-stream.c +++ b/lib/kunit/string-stream.c @@ -173,7 +173,7 @@ void string_stream_destroy(struct string_stream *stream) { KUNIT_STATIC_STUB_REDIRECT(string_stream_destroy, stream); - if (!stream) + if (IS_ERR_OR_NULL(stream)) return; string_stream_clear(stream); -- 2.30.2