All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Marc Kleine-Budde <mkl@pengutronix.de>, linux-can@vger.kernel.org
Cc: kernel@pengutronix.de
Subject: Re: [PATCH 13/14] can: make use of preallocated can_ml_priv for per device struct can_dev_rcv_lists
Date: Thu, 24 Aug 2017 15:55:24 +0200	[thread overview]
Message-ID: <190a854e-9264-0850-4d6a-8c0001016cc6@hartkopp.net> (raw)
In-Reply-To: <20170802174434.4689-14-mkl@pengutronix.de>



On 08/02/2017 07:44 PM, Marc Kleine-Budde wrote:

>   static struct can_dev_rcv_lists *can_dev_rcv_lists_find(struct net *net,
>   							struct net_device *dev)
>   {
> -	if (!dev)
> +	if (dev) {
> +		struct can_ml_priv *ml_priv = dev->ml_priv;
> +		return &ml_priv->dev_rcv_lists;
> +	} else {
>   		return net->can.can_rx_alldev_list;
> -	else
> -		return (struct can_dev_rcv_lists *)dev->ml_priv;
> +	}
>   }

I would not change the condition in the if-statement and the code order.

>   
>   /**
> @@ -589,12 +592,6 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,
>   	if (can_pstats->rcv_entries > 0)
>   		can_pstats->rcv_entries--;
>   
> -	/* remove device structure requested by NETDEV_UNREGISTER */
> -	if (dev_rcv_lists->remove_on_zero_entries && !dev_rcv_lists->entries) {
> -		kfree(dev_rcv_lists);
> -		dev->ml_priv = NULL;
> -	}
> -
>    out:
>   	spin_unlock(&net->can.can_rcvlists_lock);
>   
> @@ -827,7 +824,6 @@ static int can_notifier(struct notifier_block *nb, unsigned long msg,
>   			void *ptr)
>   {
>   	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
> -	struct can_dev_rcv_lists *dev_rcv_lists;
>   
>   	if (dev->type != ARPHRD_CAN)
>   		return NOTIFY_DONE;
> @@ -835,33 +831,8 @@ static int can_notifier(struct notifier_block *nb, unsigned long msg,
>   	switch (msg) {
>   
>   	case NETDEV_REGISTER:
> -
> -		/* create new dev_rcv_lists for this device */
> -		dev_rcv_lists = kzalloc(sizeof(*dev_rcv_lists), GFP_KERNEL);
> -		if (!dev_rcv_lists)
> -			return NOTIFY_DONE;
> -		BUG_ON(dev->ml_priv);
> -		dev->ml_priv = dev_rcv_lists;
> -
> -		break;
> -
> -	case NETDEV_UNREGISTER:
> -		spin_lock(&dev_net(dev)->can.can_rcvlists_lock);
> -
> -		dev_rcv_lists = dev->ml_priv;
> -		if (dev_rcv_lists) {
> -			if (dev_rcv_lists->entries)
> -				dev_rcv_lists->remove_on_zero_entries = 1;
> -			else {
> -				kfree(dev_rcv_lists);
> -				dev->ml_priv = NULL;
> -			}
> -		} else
> -			pr_err("can: notifier: receive list not found for dev "
> -			       "%s\n", dev->name);
> -
> -		spin_unlock(&dev_net(dev)->can.can_rcvlists_lock);
> -
> +		WARN(!dev->ml_priv,
> +		     "No CAN mid layer private allocated, please fix your driver and use alloc_candev()!\n");

Nice :-)

>   		break;
>   	}
>   
> diff --git a/net/can/af_can.h b/net/can/af_can.h
> index 4b77c7951f17..dc198a07a8d1 100644
> --- a/net/can/af_can.h
> +++ b/net/can/af_can.h
> @@ -71,7 +71,6 @@ struct can_dev_rcv_lists {
>   	struct hlist_head rx[RX_MAX];
>   	struct hlist_head rx_sff[CAN_SFF_RCV_ARRAY_SZ];
>   	struct hlist_head rx_eff[CAN_EFF_RCV_ARRAY_SZ];
> -	int remove_on_zero_entries;
>   	int entries;
>   };
>   
> 

  reply	other threads:[~2017-08-24 13:58 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 17:44 [00/14] can: cleanup of af_can/raw + simplifying of ndev->ml_priv handling Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 01/14] can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL Marc Kleine-Budde
2017-08-24 12:42   ` Oliver Hartkopp
2017-08-25  8:31     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 02/14] can: give structs holding the CAN statistics a sensible name Marc Kleine-Budde
2017-08-24 12:58   ` Oliver Hartkopp
2017-08-25 13:08     ` Marc Kleine-Budde
2017-08-25 17:32       ` Oliver Hartkopp
2017-08-28  7:25         ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 03/14] can: af_can: give struct holding the CAN per device receive lists " Marc Kleine-Budde
2017-08-24 12:59   ` Oliver Hartkopp
2017-08-28 10:58     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 04/14] can: af_can: give variable " Marc Kleine-Budde
2017-08-24 13:03   ` Oliver Hartkopp
2017-08-28 13:39     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 05/14] can: proc: " Marc Kleine-Budde
2017-08-24 13:05   ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 06/14] can: af_can: rename find_rcv_list() to can_rcv_list_find() Marc Kleine-Budde
2017-08-24 13:11   ` Oliver Hartkopp
2017-08-28 11:53     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 07/14] can: af_can: give variable holding the CAN receiver and the receiver list a sensible name Marc Kleine-Budde
2017-08-24 13:27   ` Oliver Hartkopp
2017-08-28 15:24     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 08/14] can: af_can: can_rx_register(): use max() instead of open coding it Marc Kleine-Budde
2017-08-24 13:28   ` Oliver Hartkopp
2017-08-28 15:24     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 09/14] can: raw: use struct sock::sk_bound_dev_if instead of struct raw_sock::ifindex Marc Kleine-Budde
2017-08-24 13:39   ` Oliver Hartkopp
2017-08-24 14:11     ` Kurt Van Dijck
2017-08-25  8:43       ` Oliver Hartkopp
2017-08-25  9:34         ` Kurt Van Dijck
2017-08-25 17:54           ` Oliver Hartkopp
2017-08-25 18:46             ` Kurt Van Dijck
2017-08-27 14:27               ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 10/14] can: raw: raw_bind: bail out if can_family is not AF_CAN Marc Kleine-Budde
2017-08-24 13:40   ` Oliver Hartkopp
2017-08-28 15:25     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 11/14] can: af_can: can_pernet_exit(): no need to iterate over and cleanup registered CAN devices Marc Kleine-Budde
2017-08-24 13:48   ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 12/14] can: introduce CAN midlayer private and allocate it automatically Marc Kleine-Budde
2017-08-24 13:51   ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 13/14] can: make use of preallocated can_ml_priv for per device struct can_dev_rcv_lists Marc Kleine-Budde
2017-08-24 13:55   ` Oliver Hartkopp [this message]
2017-08-02 17:44 ` [PATCH 14/14] can: af_can: remove NULL-ptr checks from users of can_dev_rcv_lists_find() Marc Kleine-Budde
2017-08-24 13:58   ` Oliver Hartkopp
2017-08-03  5:03 ` [00/14] can: cleanup of af_can/raw + simplifying of ndev->ml_priv handling Oliver Hartkopp
2017-08-03  7:39   ` Marc Kleine-Budde
2017-08-17 11:57   ` Marc Kleine-Budde
2017-08-17 12:57     ` Oliver Hartkopp
2017-08-17 13:02       ` Marc Kleine-Budde
2017-08-17 13:03         ` Marc Kleine-Budde
2017-08-17 13:06           ` Marc Kleine-Budde
2017-08-17 13:13             ` Oliver Hartkopp
2017-08-17 13:17               ` Marc Kleine-Budde
2017-08-17 13:54                 ` Oliver Hartkopp
2017-08-17 14:08                   ` Marc Kleine-Budde
2017-08-24 12:31                     ` Oliver Hartkopp
2017-08-17 13:08         ` Oliver Hartkopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=190a854e-9264-0850-4d6a-8c0001016cc6@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.