| Message ID | 20220608165116.1575390-6-dario.binacchi@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-amarula+bncBCQ4XFG47UFRBE5HQOKQMGQEL4JRM5I@amarulasolutions.com> X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 475863F1F7 for <linux-amarula@patchwork.amarulasolutions.com>; Wed, 8 Jun 2022 18:51:32 +0200 (CEST) Received: by mail-ej1-f72.google.com with SMTP id kf3-20020a17090776c300b0070d149300e9sf7261529ejc.15 for <linux-amarula@patchwork.amarulasolutions.com>; Wed, 08 Jun 2022 09:51:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707092; cv=pass; d=google.com; s=arc-20160816; b=PCqvguRS0J5+XuUw0y09NrRdDA7XGqWro1EWjA1BKKqY+sPQs4gge9MjibAjbocaSI pJQAVNGDOx6x3WNNzHcuiOUl15vytOElnWZLkAXHncAZvCgNL5tcz6FTEVmLIAU2B4CM YF5F2a9mRS/GowB1P63m6CnqnOmc0e0eYhzJeR+YKv1nqBLl4PjLJSgwFRR0NPBm+fkN RkJMtZpl1g6o/LWyWUapijMghMn9syz77b48PWerUNVkZvbi97IbPFNuB38EjOUmrpqE kM+EJ/ExOaYEha8wc7pkFApRo3K06ujkZJvIdVQZIgi39f6RRJwrSXjY34cW5cJ0Sb5h cVAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=P8ZhUhw6Omd+dPqzp4pqpCei5+ghTSMLtFuHyIRHMycjWMjBwJujkJTZ8oKCeCnoIZ UWwoQJLoRqAAJTbRkMVU9vC5bLSxGtevwKjnE+x/5t0YJoc1iOZ4CQQowaX8orWN0D+2 Fz3hWJ+66x1Hq5oop/HP6uDTnA+/FuDdznT2bFCoFimMaHvUWQpq/BVaGrJ5zG7CDzPW iztxOkzVd2mL6hYWU37j/1rsk7DyOBQjqRpp+dAQOU6zZ9n35dSOqiXJOmB2MgyFSdLi SdV+NzCvRs6J8yPq95DV5VnZ87vg/7VAWB2vBACERgTmIIGv0J1TPcdZ3toYmv+xorTb RU3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EbNQlONL; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=j8z6mmC8d4aJS1QclK/Sx5PtG/x2mIgJ4naklo57mlCe6TvGbAhOQjv/dDMKNJKvuV VApxILYcCa5jSQLDLTRa7u1xYYHhl9wIGy5Vdw7XspMnLVE8VYKn4LdOJALjDojNhol+ aBoWVtrukmrf700IJv2ZEQh0KKOft/zB6Eolw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=dnCzPY6STum6y3H4fySaIlCLaVvsqQN2RRnZjH91iy4=; b=lG4CVS26T992wWnsKy/cLMSi5xK/fE5U4J+ce7G0FqLGwkLJkYT1wCeiWR96KJ4CLw kRTBucDFBtqh3cpUmpnlpi6pGenKdeYIEcRTTkBJwPxBJmyVgwwDDehvOt1cmHzJYvLO /CW9aeUghDIJMrETKeVXygyE23+Rq7pSeWTB9ATCQJuhM8IOIjj3/6FQ3ZJ2jIfYuZ2q imLpWGi/SmjI1m6JZffNmO7ZVd9jSSaWVwKmBPtrrkSe060fiz4MjYMC5VDbyJL0Jj2S kJYfHeDT7jDfdqK3Vxt8xuEkkGlAKyJOrcw9oTLVBRe3ES/RsNBWoBeAUPre5IZ2oRKV 2OiQ== X-Gm-Message-State: AOAM533wS0mercnRKdFmihBnmIbU/d4OfNhGUadJnnzm1XNQJ4C0tWpr eRxSdM7JlR9vUCS+fdNpPo7Ejpbk X-Google-Smtp-Source: ABdhPJw7Ksl7qNx7zNMvX7F+gs7UKG1BowxMIPIiiHYeBJllnk19hLx7xV2Y1RJnT8rh2u7nNnEScg== X-Received: by 2002:a17:907:72ca:b0:6f9:8675:6a2a with SMTP id du10-20020a17090772ca00b006f986756a2amr32650902ejc.98.1654707092100; Wed, 08 Jun 2022 09:51:32 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6a26:b0:70a:1088:57d1 with SMTP id qw38-20020a1709066a2600b0070a108857d1ls1236926ejc.3.gmail; Wed, 08 Jun 2022 09:51:31 -0700 (PDT) X-Received: by 2002:a17:906:52c7:b0:6ce:a880:50a3 with SMTP id w7-20020a17090652c700b006cea88050a3mr32466555ejn.437.1654707091023; Wed, 08 Jun 2022 09:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707091; cv=none; d=google.com; s=arc-20160816; b=e3flWMP8wKCbE6mO9Wnk8MCTy4gPyiwiD5LwlmGKaliDKi53f+ecsohk1At3JmcHsa yBbkPgWXMPmu3W9ujoL6DhYYPANIhoQSYLuQp66NmfEdqhm1BNV4WgqEmzQtg+XiuTKI DUV+AEaPNbDpawsjy7qzyTAYahHfvdQS7Qx4d5Suv7Aqy/wF5ILeLB+wMYfwqWD4nvQ0 GDQadWtlaA0+PwbVnWMY8aKc/+W+q5pyT8Wo1vQBLjbI5HYW3iMP6NlvjgQhyFTIJDHw Yphv2dDxD7D+KvdBLibZA0RoXClB3Ovo46ZmmWuZRIhVF7I5J6O6eh9RcMhz07MrLCFw kPKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=nVyQpX+Yrz3qKt1Nh+jQPIqCDb+sgmjzafkew5xQQck=; b=VQxBBSI4DsEWCToXyNYyxaqZqdDkJnRZ9Mvh3Zp4GxLxv2AmxsljWbR4P+/YgsICAd qjP78Db/1P9sKPgm/U0372LctTIfT148YqhK71az8hgZIn74BphIUD52bbGSR0DMn6Sl 9BAPpoXjQqOf+GPdDcA9xClC9TQSiz8N6wkQeE5Xdes5Zxe2rLsAt3rbxQy2nq4a3zwJ uxZqZ24EWnlc1EC8rlVIQ3rDR2U5dijW5AByfrd8sYTvaUTK2OZJD2Hlok9829L6HAPO GYotz6KHyhCozlKKGNDzCXdb19KeMR5sMWLJSRspwnwC2j/yP+lj0lhpXHQaLAKOGwSB fzsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EbNQlONL; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id p23-20020a170907911700b00711eea1f458sor1707183ejq.30.2022.06.08.09.51.31 for <linux-amarula@amarulasolutions.com> (Google Transport Security); Wed, 08 Jun 2022 09:51:31 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:6e13:b0:711:c722:4fc with SMTP id sd19-20020a1709076e1300b00711c72204fcmr18014645ejc.253.1654707090839; Wed, 08 Jun 2022 09:51:30 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:30 -0700 (PDT) From: Dario Binacchi <dario.binacchi@amarulasolutions.com> To: linux-kernel@vger.kernel.org Cc: Amarula patchwork <linux-amarula@amarulasolutions.com>, michael@amarulasolutions.com, Dario Binacchi <dario.binacchi@amarulasolutions.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Marc Kleine-Budde <mkl@pengutronix.de>, Paolo Abeni <pabeni@redhat.com>, Wolfgang Grandegger <wg@grandegger.com>, linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 05/13] can: slcan: simplify the device de-allocation Date: Wed, 8 Jun 2022 18:51:08 +0200 Message-Id: <20220608165116.1575390-6-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EbNQlONL; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: <linux-amarula.amarulasolutions.com> X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>, <mailto:linux-amarula@amarulasolutions.com> List-Help: <https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>, <mailto:linux-amarula+help@amarulasolutions.com> List-Archive: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/> List-Unsubscribe: <mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>, <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe> |
| Series |
can: slcan: extend supported features
|
|
Commit Message
Dario Binacchi
June 8, 2022, 4:51 p.m. UTC
Since slcan_devs array contains the addresses of the created devices, I
think it is more natural to use its address to remove it from the list.
It is not necessary to store the index of the array that points to the
device in the driver's private data.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
(no changes since v1)
drivers/net/can/slcan.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
Comments
This patch (at least) needs some rework.
The patch cf124db566e6b036 ("net: Fix inconsistent teardown and release
of private netdev state.") from DaveM added some priv_destructor
dev->priv_destructor = sl_free_netdev;
which is not taken into account in this patch.
As written before I would like to discuss this change out of your patch
series "can: slcan: extend supported features" as it is no slcan feature
extension AND has to be synchronized with the drivers/net/slip/slip.c
implementation.
When it has not real benefit and introduces more code and may create
side effects, this beautification should probably be omitted at all.
Thanks,
Oliver
On 08.06.22 18:51, Dario Binacchi wrote:
> Since slcan_devs array contains the addresses of the created devices, I
> think it is more natural to use its address to remove it from the list.
> It is not necessary to store the index of the array that points to the
> device in the driver's private data.
>
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> ---
>
> (no changes since v1)
>
> drivers/net/can/slcan.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
> index 929cb55e08af..cf05c30b8da5 100644
> --- a/drivers/net/can/slcan.c
> +++ b/drivers/net/can/slcan.c
> @@ -432,11 +432,17 @@ static int slc_open(struct net_device *dev)
>
> static void slc_dealloc(struct slcan *sl)
> {
> - int i = sl->dev->base_addr;
> + unsigned int i;
>
> - free_candev(sl->dev);
> - if (slcan_devs)
> - slcan_devs[i] = NULL;
> + for (i = 0; i < maxdev; i++) {
> + if (sl->dev == slcan_devs[i]) {
> + free_candev(sl->dev);
> + slcan_devs[i] = NULL;
> + return;
> + }
> + }
> +
> + pr_err("slcan: can't free %s resources\n", sl->dev->name);
> }
>
> static int slcan_change_mtu(struct net_device *dev, int new_mtu)
> @@ -533,7 +539,6 @@ static struct slcan *slc_alloc(void)
>
> snprintf(dev->name, sizeof(dev->name), "slcan%d", i);
> dev->netdev_ops = &slc_netdev_ops;
> - dev->base_addr = i;
> sl = netdev_priv(dev);
>
> /* Initialize channel control data */
>
Hi, On Wed, Jun 8, 2022 at 10:38 PM Oliver Hartkopp <socketcan@hartkopp.net> wrote: > > This patch (at least) needs some rework. Any suggestions are welcome. And double-checking the patch, I already have some changes to put in version 3. > > The patch cf124db566e6b036 ("net: Fix inconsistent teardown and release > of private netdev state.") from DaveM added some priv_destructor > > dev->priv_destructor = sl_free_netdev; > > which is not taken into account in this patch. > > As written before I would like to discuss this change out of your patch > series "can: slcan: extend supported features" as it is no slcan feature > extension AND has to be synchronized with the drivers/net/slip/slip.c > implementation. Why do you need to synchronize it with drivers/net/slip/slip.c implementation ? > > When it has not real benefit and introduces more code and may create > side effects, this beautification should probably be omitted at all. > I totally agree with you. I would have already dropped it if this patch didn't make sense. But since I seem to have understood that this is not the case, I do not understand why it cannot be improved in this series. The cover letter highlighted positive reactions to the series because the module had been requiring these kinds of changes for quite some time. So, why not take the opportunity to finalize this patch in this series even if it doesn't extend the supported features ? Anyway, I have some changes and tests to run before submitting version 3. If I don't get any hints before then, I'll drop it from the series. Thanks and regards, Dario > Thanks, > Oliver > > On 08.06.22 18:51, Dario Binacchi wrote: > > Since slcan_devs array contains the addresses of the created devices, I > > think it is more natural to use its address to remove it from the list. > > It is not necessary to store the index of the array that points to the > > device in the driver's private data. > > > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > > --- > > > > (no changes since v1) > > > > drivers/net/can/slcan.c | 15 ++++++++++----- > > 1 file changed, 10 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c > > index 929cb55e08af..cf05c30b8da5 100644 > > --- a/drivers/net/can/slcan.c > > +++ b/drivers/net/can/slcan.c > > @@ -432,11 +432,17 @@ static int slc_open(struct net_device *dev) > > > > static void slc_dealloc(struct slcan *sl) > > { > > - int i = sl->dev->base_addr; > > + unsigned int i; > > > > - free_candev(sl->dev); > > - if (slcan_devs) > > - slcan_devs[i] = NULL; > > + for (i = 0; i < maxdev; i++) { > > + if (sl->dev == slcan_devs[i]) { > > + free_candev(sl->dev); > > + slcan_devs[i] = NULL; > > + return; > > + } > > + } > > + > > + pr_err("slcan: can't free %s resources\n", sl->dev->name); > > } > > > > static int slcan_change_mtu(struct net_device *dev, int new_mtu) > > @@ -533,7 +539,6 @@ static struct slcan *slc_alloc(void) > > > > snprintf(dev->name, sizeof(dev->name), "slcan%d", i); > > dev->netdev_ops = &slc_netdev_ops; > > - dev->base_addr = i; > > sl = netdev_priv(dev); > > > > /* Initialize channel control data */ > >
On Sat, 11 Jun 2022 12:46:04 +0200 Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote: > > As written before I would like to discuss this change out of your > > patch series "can: slcan: extend supported features" as it is no > > slcan feature extension AND has to be synchronized with the > > drivers/net/slip/slip.c implementation. > > Why do you need to synchronize it with drivers/net/slip/slip.c > implementation ? Because slcan.c is a derivative of slip.c and the code still looks *very* similar, so improvements in one file should be ported to the other and vice versa. This has happened several times now. > > When it has not real benefit and introduces more code and may create > > side effects, this beautification should probably be omitted at all. > > > > I totally agree with you. I would have already dropped it if this > patch didn't make sense. But since I seem to have understood that > this is not the case, I do not understand why it cannot be improved > in this series. This series is mostly about adding netlink support. If there is a point of contention about a beautification, it may be easier to discuss that separately, so the netlink code can be merged while the beautification is still being discussed. On another note, the global array of slcan_devs is really unnecessary and maintaining it is a mess - as seen in some of your patches, that have to account for it in tons of places and get complicated because of it. slcan_devs is probably grandfathered from a very old kernel, since slip.c is about 30 years old, so I suggest to remove it entirely. In fact, it may be easier to patch slcan_devs away first, and that will simplify your open/close patches - your decision :) If you wish to implement the slcan_devs removal, here are some hints: The private struct can just be allocated as part of struct can_priv in slcan_open(), like so: struct net_device *dev; dev = alloc_candev(sizeof(struct slcan), 0); And then accessed like so: struct slcan *sl = netdev_priv(dev); Make sure to add struct can_priv as the first member of struct slcan: /* This must be the first member when using alloc_candev() */ struct can_priv can; > The cover letter highlighted positive reactions to the series because > the module had been requiring these kinds of changes for quite > some time. So, why not take the opportunity to finalize this patch in > this series even if it doesn't extend the supported features ? Because... I can only speak for myself, but I'd merge all the unambiguous stuff first and discuss the difficult stuff later, if there are no interdependencies :) Max
On 12.06.22 18:23, Max Staudt wrote: > On Sat, 11 Jun 2022 12:46:04 +0200 > Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote: > >>> As written before I would like to discuss this change out of your >>> patch series "can: slcan: extend supported features" as it is no >>> slcan feature extension AND has to be synchronized with the >>> drivers/net/slip/slip.c implementation. >> >> Why do you need to synchronize it with drivers/net/slip/slip.c >> implementation ? > > Because slcan.c is a derivative of slip.c and the code still looks > *very* similar, so improvements in one file should be ported to the > other and vice versa. This has happened several times now. > > >>> When it has not real benefit and introduces more code and may create >>> side effects, this beautification should probably be omitted at all. >>> >> >> I totally agree with you. I would have already dropped it if this >> patch didn't make sense. But since I seem to have understood that >> this is not the case, I do not understand why it cannot be improved >> in this series. > > This series is mostly about adding netlink support. If there is a point > of contention about a beautification, it may be easier to discuss that > separately, so the netlink code can be merged while the beautification > is still being discussed. > > > On another note, the global array of slcan_devs is really unnecessary > and maintaining it is a mess - as seen in some of your patches, that > have to account for it in tons of places and get complicated because of > it. > > slcan_devs is probably grandfathered from a very old kernel, since > slip.c is about 30 years old, so I suggest to remove it entirely. In > fact, it may be easier to patch slcan_devs away first, and that will > simplify your open/close patches - your decision :) > > > If you wish to implement the slcan_devs removal, here are some hints: > > The private struct can just be allocated as part of struct can_priv in > slcan_open(), like so: > > struct net_device *dev; > dev = alloc_candev(sizeof(struct slcan), 0); > > And then accessed like so: > > struct slcan *sl = netdev_priv(dev); > > Make sure to add struct can_priv as the first member of struct slcan: > > /* This must be the first member when using alloc_candev() */ > struct can_priv can; > > >> The cover letter highlighted positive reactions to the series because >> the module had been requiring these kinds of changes for quite >> some time. So, why not take the opportunity to finalize this patch in >> this series even if it doesn't extend the supported features ? > > Because... I can only speak for myself, but I'd merge all the > unambiguous stuff first and discuss the difficult stuff later, if there > are no interdependencies :) > > > > Max > Thanks for stepping in Max! Couldn't have summarized it better ;-) When I created slcan.c from slip.c this line discipline driver was just oriented at the SLIP idea including the user space tools to attach the network device to the serial tty. Therefore the driver took most of the mechanics (like the slcan_devs array) and did *only* the 'struct canframe' to ASCII conversion (and vice versa). @Dario: Implementing the CAN netlink API with open/close/bitrate-setting is a nice improvement. Especially as you wrote that you took care about the former/old API with slcan_attach/slcand. Best regards, Oliver
On Sun, Jun 12, 2022 at 7:13 PM Oliver Hartkopp <socketcan@hartkopp.net> wrote: > > > > On 12.06.22 18:23, Max Staudt wrote: > > On Sat, 11 Jun 2022 12:46:04 +0200 > > Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote: > > > >>> As written before I would like to discuss this change out of your > >>> patch series "can: slcan: extend supported features" as it is no > >>> slcan feature extension AND has to be synchronized with the > >>> drivers/net/slip/slip.c implementation. > >> > >> Why do you need to synchronize it with drivers/net/slip/slip.c > >> implementation ? > > > > Because slcan.c is a derivative of slip.c and the code still looks > > *very* similar, so improvements in one file should be ported to the > > other and vice versa. This has happened several times now. > > > > > >>> When it has not real benefit and introduces more code and may create > >>> side effects, this beautification should probably be omitted at all. > >>> > >> > >> I totally agree with you. I would have already dropped it if this > >> patch didn't make sense. But since I seem to have understood that > >> this is not the case, I do not understand why it cannot be improved > >> in this series. > > > > This series is mostly about adding netlink support. If there is a point > > of contention about a beautification, it may be easier to discuss that > > separately, so the netlink code can be merged while the beautification > > is still being discussed. > > > > > > On another note, the global array of slcan_devs is really unnecessary > > and maintaining it is a mess - as seen in some of your patches, that > > have to account for it in tons of places and get complicated because of > > it. > > > > slcan_devs is probably grandfathered from a very old kernel, since > > slip.c is about 30 years old, so I suggest to remove it entirely. In > > fact, it may be easier to patch slcan_devs away first, and that will > > simplify your open/close patches - your decision :) > > > > > > If you wish to implement the slcan_devs removal, here are some hints: > > > > The private struct can just be allocated as part of struct can_priv in > > slcan_open(), like so: > > > > struct net_device *dev; > > dev = alloc_candev(sizeof(struct slcan), 0); > > > > And then accessed like so: > > > > struct slcan *sl = netdev_priv(dev); > > > > Make sure to add struct can_priv as the first member of struct slcan: > > > > /* This must be the first member when using alloc_candev() */ > > struct can_priv can; > > > > > >> The cover letter highlighted positive reactions to the series because > >> the module had been requiring these kinds of changes for quite > >> some time. So, why not take the opportunity to finalize this patch in > >> this series even if it doesn't extend the supported features ? > > > > Because... I can only speak for myself, but I'd merge all the > > unambiguous stuff first and discuss the difficult stuff later, if there > > are no interdependencies :) > > > > > > > > Max > > > > Thanks for stepping in Max! > > Couldn't have summarized it better ;-) > > When I created slcan.c from slip.c this line discipline driver was just > oriented at the SLIP idea including the user space tools to attach the > network device to the serial tty. > > Therefore the driver took most of the mechanics (like the slcan_devs > array) and did *only* the 'struct canframe' to ASCII conversion (and > vice versa). > > @Dario: Implementing the CAN netlink API with open/close/bitrate-setting > is a nice improvement. Especially as you wrote that you took care about > the former/old API with slcan_attach/slcand. > > Best regards, > Oliver Thanks to both of you for the explanations. best regards, Dario
diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index 929cb55e08af..cf05c30b8da5 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -432,11 +432,17 @@ static int slc_open(struct net_device *dev) static void slc_dealloc(struct slcan *sl) { - int i = sl->dev->base_addr; + unsigned int i; - free_candev(sl->dev); - if (slcan_devs) - slcan_devs[i] = NULL; + for (i = 0; i < maxdev; i++) { + if (sl->dev == slcan_devs[i]) { + free_candev(sl->dev); + slcan_devs[i] = NULL; + return; + } + } + + pr_err("slcan: can't free %s resources\n", sl->dev->name); } static int slcan_change_mtu(struct net_device *dev, int new_mtu) @@ -533,7 +539,6 @@ static struct slcan *slc_alloc(void) snprintf(dev->name, sizeof(dev->name), "slcan%d", i); dev->netdev_ops = &slc_netdev_ops; - dev->base_addr = i; sl = netdev_priv(dev); /* Initialize channel control data */