Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp393628pxt; Fri, 6 Aug 2021 04:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye03NqO3+Ibhxrns4rLNpzfHgPSWe5jXzPGbc+jCb8LTemvUi4eo/hxB6RZoQJIDQV+XHg X-Received: by 2002:a02:2307:: with SMTP id u7mr9456815jau.28.1628250405674; Fri, 06 Aug 2021 04:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628250405; cv=none; d=google.com; s=arc-20160816; b=wLLFLvFEIv5RfFKNaAxhVOKzC1e+2H1XYhfTPxRvUB7NRRuUd16UZv3t0Az+gufLcd piVDHF92N3dxFCcCmHh8BdrTrWs0xlfHIgZxvw1z+959sqjLKcRXlaE7BKvLQvZMzA1v 6zKkBnbN2W8zTRasuDkQgA+dfUc3JYyRfiH+Sm1v+5OqdVyeke3jYiu7g3LXoE1EycKC 6ZOoBOL32C9TDh4HHhkpLC+IepFoGWssd8+EMOdjf0joKXh22hWV4HMFnPHliDh3R36S g/WlvIFSKuznc8TQ7Mezyt6tc89iyQnsksPrNh/ifWjY66pqlLYSg6pv5bFGaVYTyVyG /PJw== 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=SbevIza4EhMSBMVlDXsk7z2l6BXlmPukSRKdAQD1lug=; b=pINdTR2GGMnAX82U2H3Ax2IjhDSnfL0lRQAq8f1wUeBcWouExX5qVqYn8tUHhcvoKT V3+WJ/NfrLETmE+hN5JQw50c8E+fXnazFeXiOhunSlkMew9L5Fm3sgbi3Dv2mRGT9T/B JWGDe38sxslxmGwVHkBCZijwrQAiGlkNTUyZy3Uw60rsvH7HomXcm0I48C/aQUU0lf81 HJ8FJGIw+DxfOUtMyNmc2Tfyj3eBIE5zsiIe7UevOrYlECBklX26PIRww0AdaxyJMjot Ox80Af5wdwLboq0SGKqjqwmglKEOYSlmaqOtKGV7JDrmM1EUx/3oRHkvPlUrZxpMxNjS oo0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ddNGYfZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si8914769jaq.37.2021.08.06.04.46.33; Fri, 06 Aug 2021 04:46:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ddNGYfZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243366AbhHFGir (ORCPT + 99 others); Fri, 6 Aug 2021 02:38:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbhHFGir (ORCPT ); Fri, 6 Aug 2021 02:38:47 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F2F8C061798; Thu, 5 Aug 2021 23:38:32 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1628231910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=SbevIza4EhMSBMVlDXsk7z2l6BXlmPukSRKdAQD1lug=; b=ddNGYfZJz3UMAEfpBMCPrl5drFdErz6UokOO+ZmhNKnRA848g1+P+at0VM14Shzf3Vv5Ii PfZmNYw7R5ekART9vkQ8IvcZ6HODhvnB50lTET6u5bcWKMMlTMoQkUHzSXlRsknshKUHxP wHwyFErAWymFU0SMts9MllntxtgOSlk= From: Yajun Deng To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH net-next] net: sock: add the case if sk is NULL Date: Fri, 6 Aug 2021 14:38:15 +0800 Message-Id: <20210806063815.21541-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the case if sk is NULL in sock_{put, hold}, The caller is free to use it. Signed-off-by: Yajun Deng --- include/net/sock.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 6e761451c927..8821ec0d4147 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -699,7 +699,8 @@ static inline bool __sk_del_node_init(struct sock *sk) static __always_inline void sock_hold(struct sock *sk) { - refcount_inc(&sk->sk_refcnt); + if (sk) + refcount_inc(&sk->sk_refcnt); } /* Ungrab socket in the context, which assumes that socket refcnt @@ -1811,7 +1812,7 @@ void sock_init_data(struct socket *sock, struct sock *sk); /* Ungrab socket and destroy it, if it was the last reference. */ static inline void sock_put(struct sock *sk) { - if (refcount_dec_and_test(&sk->sk_refcnt)) + if (sk && refcount_dec_and_test(&sk->sk_refcnt)) sk_free(sk); } /* Generic version of sock_put(), dealing with all sockets -- 2.32.0