[RFC,v2,03/13] can: slcan: use the alloc_can_skb() helper

Message ID 20220602160434.225417-4-dario.binacchi@amarulasolutions.com
State New
Headers show
Series
  • can: slcan: extend supported features
Related show

Commit Message

Dario Binacchi June 2, 2022, 4:04 p.m. UTC
It is used successfully by most (if not all) CAN device drivers. It
allows to remove replicated code.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

(no changes since v1)

 drivers/net/can/slcan.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

Patch

diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
index 6162a9c21672..964b02f321ab 100644
--- a/drivers/net/can/slcan.c
+++ b/drivers/net/can/slcan.c
@@ -54,6 +54,7 @@ 
 #include <linux/kernel.h>
 #include <linux/workqueue.h>
 #include <linux/can.h>
+#include <linux/can/dev.h>
 #include <linux/can/skb.h>
 #include <linux/can/can-ml.h>
 
@@ -143,7 +144,7 @@  static struct net_device **slcan_devs;
 static void slc_bump(struct slcan *sl)
 {
 	struct sk_buff *skb;
-	struct can_frame cf;
+	struct can_frame cf, *scf;
 	int i, tmp;
 	u32 tmpid;
 	char *cmd = sl->rbuff;
@@ -201,21 +202,11 @@  static void slc_bump(struct slcan *sl)
 		}
 	}
 
-	skb = dev_alloc_skb(sizeof(struct can_frame) +
-			    sizeof(struct can_skb_priv));
-	if (!skb)
+	skb = alloc_can_skb(sl->dev, &scf);
+	if (unlikely(!skb))
 		return;
 
-	skb->dev = sl->dev;
-	skb->protocol = htons(ETH_P_CAN);
-	skb->pkt_type = PACKET_BROADCAST;
-	skb->ip_summed = CHECKSUM_UNNECESSARY;
-
-	can_skb_reserve(skb);
-	can_skb_prv(skb)->ifindex = sl->dev->ifindex;
-	can_skb_prv(skb)->skbcnt = 0;
-
-	skb_put_data(skb, &cf, sizeof(struct can_frame));
+	memcpy(scf, &cf, sizeof(*scf));
 
 	sl->dev->stats.rx_packets++;
 	if (!(cf.can_id & CAN_RTR_FLAG))