Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp8150755rdb; Thu, 4 Jan 2024 23:19:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFQ2eg4q2J87H/cD1Tgvvkg9hJkqsxXpiW92ok04AyRcdDeZIOLaBnMVs0OTc3mA/84aLb X-Received: by 2002:a17:906:4b0f:b0:a28:cf59:60c9 with SMTP id y15-20020a1709064b0f00b00a28cf5960c9mr361297eju.258.1704439198716; Thu, 04 Jan 2024 23:19:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704439198; cv=none; d=google.com; s=arc-20160816; b=ZBdSdw02GScD+Od8S/RMhqFFxr0ts8yGt6gE4W5+fU8G4kXqZ7/oYt7RKydao7nImN nOdNORoB/9uqT1RyDbSIuJrhLeBgFP9pWACFuUCsKhoDkiL5Q+LoL53VJvlj8vooXNtC bv9iblIf2kZBELifsY4B9caDHS8Vn3zaocMYmrQpKQonupw2SqpUlvWy4hJ4U7Exq0MO +gC9MT7Z6ooLYwpNkBCF9tIvt9otWu1f6O3TsYx0Nq6YIFTs7DxrbWY/XC4HqWL7eRTe RP1JuuSqwiVwz5NVShwZiP9035L3+awBNeCC3ZXMqhW7F5Mrku6Q6VpSVedVpgB3tCml TPdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=nnbd4NNKlxIwd09RppD3PPXEsR2CI47y98ZUeI58Kjg=; fh=Kta/Gzca+864t9M1gW4e9J3YmB+w5pgTf069gbsYO6E=; b=MiSVEWv52h+ZxNfn05aiNU91VEuALXbN3FHaL6nj/52mPHFGiph6HfYqpGUIgjUaMn sfdZRHbRGTMLCubYieW5USvNA3x864hdNAkx8pG9Iz4qgyZzorT5Alke38HfXU2+3KdT eCSxYgGgG1lpVRSMy7fobQfdwjJ1FCDTeN/f4G9nlLgydN0pohiAVION+3E8b8vUTxPb q5ZWfNgqkDFBnf1FrzgWFBfmmn8LUy0agscYMgRSGw3olwc2wN3lMCSiAEVXjis4Q9g3 IJ1Id+xZAhbrWVmRk5iMWZjL+udnDYjN2zi5w/OQvw9Yq3Oyt7jFsDpi1Mch7JZ9Odwq eflg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=V68hIClb; spf=pass (google.com: domain of linux-kernel+bounces-17542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bo20-20020a170906d05400b00a26ea1b1406si375515ejb.890.2024.01.04.23.19.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 23:19:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=V68hIClb; spf=pass (google.com: domain of linux-kernel+bounces-17542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6C3981F22D9E for ; Fri, 5 Jan 2024 07:19:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A28EE1EB45; Fri, 5 Jan 2024 07:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="V68hIClb" X-Original-To: linux-kernel@vger.kernel.org Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A6CE1DDDC; Fri, 5 Jan 2024 07:19:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 4057JKiM065605; Fri, 5 Jan 2024 01:19:20 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1704439160; bh=nnbd4NNKlxIwd09RppD3PPXEsR2CI47y98ZUeI58Kjg=; h=Date:Subject:To:CC:References:From:In-Reply-To; b=V68hIClb9NB4iTuZkakfWhO8/vk5DBlJFqTiIrE81l6Wq1Yqdz/8UMF4SZvLXzMFv OmpdS2yScv8n8DnYQY5SZmPYUtx/LYrdLkoBTvoYIvDPoBDjcIOkMuiZ76ARG64A1j tcbGQKQOEpVLh/pUZq4i3FKfgsjIKsIg2TwmtuFA= Received: from DFLE102.ent.ti.com (dfle102.ent.ti.com [10.64.6.23]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 4057JKaU013603 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 5 Jan 2024 01:19:20 -0600 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Fri, 5 Jan 2024 01:19:20 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Fri, 5 Jan 2024 01:19:20 -0600 Received: from [10.249.132.18] ([10.249.132.18]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4057JF5I023483; Fri, 5 Jan 2024 01:19:16 -0600 Message-ID: Date: Fri, 5 Jan 2024 12:49:14 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] net: can: Add support for aliases in CAN Content-Language: en-US To: Simon Horman CC: , , , , , , , , , , , , References: <20240102102949.138607-1-b-kapoor@ti.com> <20240104171940.GI31813@kernel.org> From: Bhavya Kapoor In-Reply-To: <20240104171940.GI31813@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 On 04/01/24 22:49, Simon Horman wrote: > On Tue, Jan 02, 2024 at 03:59:49PM +0530, Bhavya Kapoor wrote: >> When multiple CAN's are present, then names that are getting assigned >> changes after every boot even after providing alias in the device tree. >> Thus, Add support for implementing CAN aliasing so that names or >> alias for CAN will now be provided from device tree. >> >> Signed-off-by: Bhavya Kapoor > Hi Bhavya, > > some minor feedback from my side. > > ... > >> diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c >> index 3a3be5cdfc1f..ed483c23ec79 100644 >> --- a/drivers/net/can/dev/dev.c >> +++ b/drivers/net/can/dev/dev.c >> @@ -247,12 +247,14 @@ void can_setup(struct net_device *dev) >> >> /* Allocate and setup space for the CAN network device */ >> struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, >> - unsigned int txqs, unsigned int rxqs) >> + unsigned int txqs, unsigned int rxqs, >> + struct device *candev) >> { >> struct can_ml_priv *can_ml; >> struct net_device *dev; >> struct can_priv *priv; >> - int size; >> + int size, aliasid; >> + char devname[6] = "can%d"; > nit: Please consider arranging local variables in Networking code > in reverse xmas tree order - longest line to shortest. Okay, i will keep this in mind from next time. > >> >> /* We put the driver's priv, the CAN mid layer priv and the >> * echo skb into the netdevice's priv. The memory layout for >> @@ -273,7 +275,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, >> size = ALIGN(size, sizeof(struct sk_buff *)) + >> echo_skb_max * sizeof(struct sk_buff *); >> >> - dev = alloc_netdev_mqs(size, "can%d", NET_NAME_UNKNOWN, can_setup, >> + if (candev) { >> + aliasid = of_alias_get_id(candev->of_node, "can"); >> + if (aliasid >= 0) >> + snprintf(devname, sizeof(devname), "%s%d", "can", aliasid); > The size of devname is 6 bytes (can%d\0). > This means that snprintf() will truncate devname if alias is greater than 99. > Is this a concern? When sequential naming will be done from can0 in aliases for can,  considering that 99 is still a very large number and so 6 bytes for devname should suffice. Regards > If so, perhaps devname could be declared to be IFNAMSIZ bytes long? > > Flagged by gcc-13 -Wformat-truncation > >> + } >> + dev_dbg(candev, "Name of CAN assigned is : %s\n", devname); >> + >> + dev = alloc_netdev_mqs(size, devname, NET_NAME_UNKNOWN, can_setup, >> txqs, rxqs); >> if (!dev) >> return NULL; > ...