From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B34D614E2FB for ; Tue, 7 May 2024 10:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715076667; cv=none; b=I0TBBZv9fRsU9X50s1csUAutYcOSps6di6u6876EbvRLTcd28bsGCqPqfhisNCmchA898OxxRZKkr6Yh1whipiRDW41HBO3rF7qkffMTvhpr6O63nkAbHO3nNOJzGoJlNMZ3LCpnwrGqweVrrz+D0GAU5RkI9jnHwLrX2Prw6fA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715076667; c=relaxed/simple; bh=pzN0QEsi5vW51SAWCGgbkaOsqw5VvfmrBvJ7uOk7Djk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IoSpNGvVpO/yzhlLJApDtEGqZr/EXQbeD1KOgmTAYl8kqybXESr6ZalgwAGZCUkBnp8/urAgBTNzK8jcSVkjah4jumGROwnzFH2jFLiocsJoIkoXbbF9Rn5I/1EX1cbVep03BX0sBYVaJeGcfh9l1a4vBg1UIXFJz0Xz4oRf+14= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=L/QV+/dJ; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="L/QV+/dJ" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-41bab13ca81so31478625e9.1 for ; Tue, 07 May 2024 03:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715076664; x=1715681464; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xRkoNOEv8gPHcq2P5UAKWS8B3jCr0cVjdP20g/cY62k=; b=L/QV+/dJ7j42rpb8HLhc0HWVdxhS7FBN4FcTW8z4HzQMBAtZd12/MRDlMr+jaXVhzL 0gq/MQ7+jLEYc9cXq5ZI8qVm5dmGHd4lXhCx5oSmAD0wyZZQTsSuXF4gd404OL8BZBbU NMNIDoHbQWmAD2yy3JzA91DkbwbwNVAbUX0r+L4MbGiVBI7s6a3ZUCMKxkp0+OxABgo8 zEx47alEjrFV90mEneAac+26I4rlI/tvAjw2gjNCdKnrV612+JYPFHP54nvbeNXLU/ko if/JwpXjx7qxNClmWzw1EiUuY8ZdYzT6tnHBXmxbvyLUXLL9M9qQrmvW9b9uwssiE4zL 4CYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715076664; x=1715681464; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xRkoNOEv8gPHcq2P5UAKWS8B3jCr0cVjdP20g/cY62k=; b=te4+Yp0pXbDELrK4CIv58vPn6w7sQy2aeaMm7/UGojtYdOZxUsN/GmuXxntLT+nzRp AVaF9Cobvof1A0rwZ9Zl1JPy7nTN1wVp8kcGU3e2n2qhsSydRXN+Ffr97/UZayEcWWUQ 2isJD2hvsjZAYSKqdYkjVbo3GVDdIIQngSectbYDS4ODql1gij3G1dTA21t1usOmj/4c 9mi0ntZ6cByJVKWKjo8LdW/EohJol/v63o+GCe/ZgQ11kOY8AFMAOhe2nw4xRbWarWxO KhJAaZnWxQ4LePIItCsy5xIoDbS8eFeS24vtSklWJxOxp1UY7Zo6ltnyycjy/7WwsY+K y4ZA== X-Forwarded-Encrypted: i=1; AJvYcCUKJ3V+LBFK0Jd+mJIiheBc6lQUclacAPjp6MIJedZ/BVrSG4WpocC3sFZF4Cw3phJ1gtQwJ5ZbypdOdKuy9eIWhASmavOBik3T94nD X-Gm-Message-State: AOJu0YyJFKhBsD1XYP1E+gakYAY+q/Emabt/RhayIhfTxXnJFGGb0Ppg QS/ICuPvemGULp2lSYX4GCecD27XSpeWF8liWl9uZP+1yKJmV0nB5wB+fTipAZo= X-Google-Smtp-Source: AGHT+IHQFXd45hAfqA6n0d5ImUefQlbvL7vaRViI8Nu6Qp2CarjGeOlr7thOVlNJO6zr1Os/EEcwqg== X-Received: by 2002:a05:600c:1553:b0:41b:e94f:1e88 with SMTP id f19-20020a05600c155300b0041be94f1e88mr13064142wmg.24.1715076663825; Tue, 07 May 2024 03:11:03 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id n19-20020a05600c4f9300b0041c14061c71sm18935780wmq.15.2024.05.07.03.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 03:11:03 -0700 (PDT) Date: Tue, 7 May 2024 12:52:03 +0300 From: Dan Carpenter To: Ratheesh Kannoth Cc: Duoming Zhou , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hams@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, jreuter@yaina.de Subject: Re: [PATCH net v5 1/4] ax25: Use kernel universal linked list to implement ax25_dev_list Message-ID: <5863f2fc-ab8e-4f6e-873e-2667bc0a2e4b@moroto.mountain> References: <20240507092917.GA1049473@maili.marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240507092917.GA1049473@maili.marvell.com> On Tue, May 07, 2024 at 02:59:17PM +0530, Ratheesh Kannoth wrote: > On 2024-05-07 at 12:33:39, Duoming Zhou (duoming@zju.edu.cn) wrote: > > The origin ax25_dev_list implements its own single linked list, > > which is complicated and error-prone. For example, when deleting > > the node of ax25_dev_list in ax25_dev_device_down(), we have to > > operate on the head node and other nodes separately. > > > > This patch uses kernel universal linked list to replace original > > ax25_dev_list, which make the operation of ax25_dev_list easier. > > There are two points that need to notice: > > > > [1] We should add a check to judge whether the list is empty before > > INIT_LIST_HEAD in ax25_dev_device_up(), otherwise it will empty the > > list for each new ax25_dev added. > > > > [2] We should do "dev->ax25_ptr = ax25_dev;" and "dev->ax25_ptr = NULL;" > > while holding the spinlock, otherwise the ax25_dev_device_up() and > > ax25_dev_device_down() could race, we're not guaranteed to find a match > > ax25_dev in ax25_dev_device_down(). > > > > Suggested-by: Dan Carpenter > > Signed-off-by: Duoming Zhou > > -ax25_dev *ax25_dev_list; > > +static struct list_head ax25_dev_list; > > DEFINE_SPINLOCK(ax25_dev_lock); > > > > ax25_dev *ax25_addr_ax25dev(ax25_address *addr) > > @@ -34,7 +35,7 @@ ax25_dev *ax25_addr_ax25dev(ax25_address *addr) > > ax25_dev *ax25_dev, *res = NULL; > > > > spin_lock_bh(&ax25_dev_lock); > > - for (ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) > > + list_for_each_entry(ax25_dev, &ax25_dev_list, list) > > if (ax25cmp(addr, (const ax25_address *)ax25_dev->dev->dev_addr) == 0) { > > res = ax25_dev; > > ax25_dev_hold(ax25_dev); > > @@ -52,6 +53,9 @@ void ax25_dev_device_up(struct net_device *dev) > > { > > ax25_dev *ax25_dev; > > > > + /* Initialized the list for the first entry */ > > + if (!ax25_dev_list.next) > > + INIT_LIST_HEAD(&ax25_dev_list); > if you define ax25_dev_list using 'static LIST_HEAD(ax25_dev_list)', you need this conditional check and > initialization ? > Ah, yes. That's the proper way to do it. regards, dan carpenter