Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp567705pxt; Thu, 5 Aug 2021 06:34:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysOgwh0lW1GdG7aZER1DpF1sgzt709SqhNJJrnbHP8btAhc4kJGKVWYOMUUOc005iYxpjD X-Received: by 2002:a92:d7c4:: with SMTP id g4mr397539ilq.24.1628170487982; Thu, 05 Aug 2021 06:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628170487; cv=none; d=google.com; s=arc-20160816; b=xTkKNwGzeV0dCx7S9AxCbZKBPVk9G0X4yDUzDtmqzAfr7mCSBW8XYPSmMfyNpu039b HUg8H0mucR8irlW/vep4CxgVNPQHuIE/QHZVRfEJsG8+TJys9QOxLusT/fjRTjnQQU/W V7ZIO8RBnMNDHylHlJaUuq78z4oVUamKLZHnilVGOi29Ohgf05UTsROBUCHVOe8eHPoV QHS71XnWep2WV2YvEI/zEUFbZ7wHZQj+R6biDiJ4hkyyf0ANGVebf3tRYNpAFRCXWGcH 7oZw8AszW6s/gkBEib6NHIAlLiO907N3oRMDAIBPKqXyfJ8VLSCBg9muzd341Lm91JJT oqsg== 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=DWfoldmLRLq80DZdsLCKJEoZaBQ6+NbZZHi/F4hDQ/s=; b=Qx3Mk3tWHAT8IQCmh8dPxQ5yTC0s2ttmAaxilQFIUz/thnuR5p8n8ASmUC/PUc5K7e FKqIQsrA4iRtjMY0yrfdsDNDVSx+j5PfKvi3x9mWFxM9MAGdofW1jefy78UMTZe1pbCJ m10S22zJWglxJsRt/Pgx5L0p9aDl3qUAgpwJLdTHlIyADYvOOY7sp0jZx1kDCdSaba1P yoaWyUXLT8bWhvFmXJzUy7epmNr4kYnwRD1oQsrUaS2je9N6m+x2H9ffRw79T/jODooC p+T/8MsRJFJWttHuve7secxcDHUz7BokP4rsWs7hRI8k27LNkntE5No0U9O94JimOBFP WGng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qp8pE5Ns; 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 y17si8123141iov.62.2021.08.05.06.34.36; Thu, 05 Aug 2021 06:34:47 -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=qp8pE5Ns; 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 S238848AbhHELzN (ORCPT + 99 others); Thu, 5 Aug 2021 07:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbhHELzN (ORCPT ); Thu, 5 Aug 2021 07:55:13 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8848C061765; Thu, 5 Aug 2021 04:54:58 -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=1628164495; 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=DWfoldmLRLq80DZdsLCKJEoZaBQ6+NbZZHi/F4hDQ/s=; b=qp8pE5Ns0L6FGItYvYTd+qjUmHViF2N72s5huxJj0qYVBp+S1hwFf0D0p6Nuv19l7AHeMs cg4QYCgSyQ2qz1njp9zJSyxphIW6YrHoBn7kkFmao40fDhWPOOBkCK/jOGVgiVN3V4fL0e yc3ydWbJnyjB/O+sY9hNU/tuLwmsKMo= 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] netdevice: add the case if dev is NULL Date: Thu, 5 Aug 2021 19:54:34 +0800 Message-Id: <20210805115434.19248-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 dev is NULL in dev_{put, hold}, so the caller doesn't need to care whether dev is NULL or not. Signed-off-by: Yajun Deng --- include/linux/netdevice.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 1b4d4509d04b..135c943699d0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4143,11 +4143,13 @@ void netdev_run_todo(void); */ static inline void dev_put(struct net_device *dev) { + if (dev) { #ifdef CONFIG_PCPU_DEV_REFCNT - this_cpu_dec(*dev->pcpu_refcnt); + this_cpu_dec(*dev->pcpu_refcnt); #else - refcount_dec(&dev->dev_refcnt); + refcount_dec(&dev->dev_refcnt); #endif + } } /** @@ -4158,11 +4160,13 @@ static inline void dev_put(struct net_device *dev) */ static inline void dev_hold(struct net_device *dev) { + if (dev) { #ifdef CONFIG_PCPU_DEV_REFCNT - this_cpu_inc(*dev->pcpu_refcnt); + this_cpu_inc(*dev->pcpu_refcnt); #else - refcount_inc(&dev->dev_refcnt); + refcount_inc(&dev->dev_refcnt); #endif + } } /* Carrier loss detection, dial on demand. The functions netif_carrier_on -- 2.32.0