Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4785124rwe; Mon, 17 Apr 2023 19:21:51 -0700 (PDT) X-Google-Smtp-Source: AKy350axMUVOSqZ9agFJl4CmKGvXzzXjZiNgbHwrOExLg1vGPDvxLRx9ZSF3lLdVG1i0AKMbze06 X-Received: by 2002:a05:6a20:6a10:b0:f0:86ce:d02c with SMTP id p16-20020a056a206a1000b000f086ced02cmr1273243pzk.16.1681784510932; Mon, 17 Apr 2023 19:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681784510; cv=none; d=google.com; s=arc-20160816; b=Pvi4x1KX9HGVI2XuFrEJl2PHQueBmGH1cBnMOi0sIbGdlRWCTOhohgvf150tMEzWxZ wVl91UiaYdCYCPwPT2DTARZ3VJPQA0kAc7h3eYb0O32Ng6s4wu73qr9SrqDU4OGqs3XR sAj+tTH3TH3Hks1gYD9btIdARRXBHxZreLbwQCQUZ3W5Vsl7ZbFhfTVxydWAuMDHmZjm QAhym1/laLl9bqo2rV0j1qZMIK2RnP8OsiPkgNEzcUfG6/xFs9L5TekGjiOK6TCBHxQa 9KrJKFc7Hc3rT9y4MsR75dmaD1KwhMgWvud1rnuQfCC+q7c0TaQGFrJA1H/DsMa2zLh0 lszA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=r6//4p0c/K+/W2/C0D+40CXVNPs2ZKHVVrLuIubEsxk=; b=sYFqBsbg3+Kd809rH8FaJBmxKUONnhtunGTQhZlNnpcuXURdLkRwROk8HLYHp3/uMO grG70pz9KrzhsLrqsUsw08BfLeL7v/eye3qptcDOAuYgmG41SCkFT8Qw+yqpf1eSCC+k MZj9yU0DyDnQl9OYste0swjfwZpMtcx8Oinbh4i+cBUXB8SrYssL2M2TrZNGsfj0vRwK EblREKwdT7Qkz2nzFtW9wAKO06v+vGLrF/evdkA6xgYj4u/gHA/DKZjONbi/5QC8G3rx XVD257LF0wKLLtoJ4ldOGkhA4Gidm6P7BUCBscOQbQVTH1sfzoER6VGSpGDwU17Y4jCf cAbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oQnjG1WG; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z9-20020a634c09000000b0051394ca5bbdsi13521623pga.257.2023.04.17.19.21.36; Mon, 17 Apr 2023 19:21:50 -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=@kernel.org header.s=k20201202 header.b=oQnjG1WG; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbjDRCRj (ORCPT + 99 others); Mon, 17 Apr 2023 22:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjDRCRi (ORCPT ); Mon, 17 Apr 2023 22:17:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 233B2A7; Mon, 17 Apr 2023 19:17:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AEC4B62BAA; Tue, 18 Apr 2023 02:17:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7088AC433D2; Tue, 18 Apr 2023 02:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681784256; bh=RJBV+GpQnO6E09AAkDfpwLAYfeR7ZcsdzQtUcu+2ec8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=oQnjG1WG4kx0WQ3S/essGLapdxQhgOBa5eC29P93rakGeYnci1+dUW7oDKuIobB5I aL68s6Mb2L3xJdYnI+IN2Xye7GS9BCq96BKKnH6VyNTcCatsJl5VCkZIJTA6OysbyU V4t+0GmPyuDprZF/ctzObR8UGI8mIGZWH66t9hVgdQAU4mnTFMoXZYvGMUhwUqJoDl BGXXpffZ5qRJP8WMMW6gojHg2SW9G01e3aGSibWBKJRJNz0L1QND5P+DRXhs+4cCxB 1754ZRObzfkzQ2Ky3VDqf81G/UY4ATI0ws8/0NoODzZgoYlFAxb3z2GH2PHJep6IPF YNQt0XJEm9UQA== Date: Mon, 17 Apr 2023 19:17:34 -0700 From: Jakub Kicinski To: Dan Carpenter Cc: David Ahern , Haoyi Liu , "David S. Miller" , Eric Dumazet , Paolo Abeni , hust-os-kernel-patches@googlegroups.com, yalongz@hust.edu.cn, Dongliang Mu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v2] net/ipv6: silence 'passing zero to ERR_PTR()' warning Message-ID: <20230417191734.78c18a5f@kernel.org> In-Reply-To: <11c76aa6-4c19-4f1d-86dd-e94e683dbd64@kili.mountain> References: <20230413101005.7504-1-iccccc@hust.edu.cn> <11c76aa6-4c19-4f1d-86dd-e94e683dbd64@kili.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Fri, 14 Apr 2023 09:32:51 +0300 Dan Carpenter wrote: > Also it can return NULL. > > net/xfrm/xfrm_policy.c > 3229 dst = dst_orig; > 3230 } > 3231 ok: > 3232 xfrm_pols_put(pols, drop_pols); > 3233 if (dst && dst->xfrm && > ^^^ > "dst" is NULL. Don't take my word for it, but AFAICT it's impossible to get there with dst == NULL. I think we can remove this check instead if that's what makes smatch infer that dst may be NULL. > 3234 dst->xfrm->props.mode == XFRM_MODE_TUNNEL) > 3235 dst->flags |= DST_XFRM_TUNNEL; > 3236 return dst; > ^^^^^^^^^^^ > 3237 > > So in the original code what happened here was: > > net/ipv6/icmp.c > 395 dst2 = xfrm_lookup(net, dst2, flowi6_to_flowi(&fl2), sk, XFRM_LOOKUP_ICMP); > 396 if (!IS_ERR(dst2)) { > > xfrm_lookup() returns NULL. NULL is not an error pointer. > > 397 dst_release(dst); > 398 dst = dst2; > > We set "dst" to NULL. > > 399 } else { > 400 err = PTR_ERR(dst2); > 401 if (err == -EPERM) { > 402 dst_release(dst); > 403 return dst2; > 404 } else > 405 goto relookup_failed; > 406 } > 407 > 408 relookup_failed: > 409 if (dst) > 410 return dst; > > dst is not NULL so we don't return it. > > 411 return ERR_PTR(err); > > However "err" is not set so we do return NULL and Smatch complains about > that. > > Returning ERR_PTR(0); is not necessarily a bug, however 80% of the time > in newly introduced code it is a bug. Here, returning NULL is correct. > So this is a false positive, but the code is just wibbly winding and so > difficult to read. > > 412 }