lkml.org 
[lkml]   [2022]   [May]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 1/2] can: move can_dropped_invalid_skb from skb.h to dev.h
    Date
    This is a preparation patch for next change.

    We want to introduce a check towards CAN_CTRLMODE_LISTENONLY in
    can_dopped_invalid_skb(). To do so, we would need to include
    linux/can/dev.h (for struct can_priv) and uapi/linux/can/netlink.h
    (for the definition of CAN_CTRLMODE_LISTEONLY). Instead of adding
    those header and contributing to the include hell, we prever to
    relocate can_dropped_invalid_skb() to linux/can/dev.h where all the
    needed headers are already present.

    While doing so, do a small cleanup: re-indent the second line of the
    function argument and add brackets around the else block.

    Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
    ---
    include/linux/can/dev.h | 29 +++++++++++++++++++++++++++++
    include/linux/can/skb.h | 28 ----------------------------
    2 files changed, 29 insertions(+), 28 deletions(-)

    diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
    index c2ea47f30046..bbe27e22c7a7 100644
    --- a/include/linux/can/dev.h
    +++ b/include/linux/can/dev.h
    @@ -156,6 +156,35 @@ static inline u32 can_get_static_ctrlmode(struct can_priv *priv)
    return priv->ctrlmode & ~priv->ctrlmode_supported;
    }

    +/* Drop a given socketbuffer if it does not contain a valid CAN frame. */
    +static inline bool can_dropped_invalid_skb(struct net_device *dev,
    + struct sk_buff *skb)
    +{
    + const struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
    +
    + if (skb->protocol == htons(ETH_P_CAN)) {
    + if (unlikely(skb->len != CAN_MTU ||
    + cfd->len > CAN_MAX_DLEN))
    + goto inval_skb;
    + } else if (skb->protocol == htons(ETH_P_CANFD)) {
    + if (unlikely(skb->len != CANFD_MTU ||
    + cfd->len > CANFD_MAX_DLEN))
    + goto inval_skb;
    + } else {
    + goto inval_skb;
    + }
    +
    + if (!can_skb_headroom_valid(dev, skb))
    + goto inval_skb;
    +
    + return false;
    +
    +inval_skb:
    + kfree_skb(skb);
    + dev->stats.tx_dropped++;
    + return true;
    +}
    +
    void can_setup(struct net_device *dev);

    struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
    diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h
    index fdb22b00674a..985791c84a8d 100644
    --- a/include/linux/can/skb.h
    +++ b/include/linux/can/skb.h
    @@ -126,34 +126,6 @@ static inline bool can_skb_headroom_valid(struct net_device *dev,
    return true;
    }

    -/* Drop a given socketbuffer if it does not contain a valid CAN frame. */
    -static inline bool can_dropped_invalid_skb(struct net_device *dev,
    - struct sk_buff *skb)
    -{
    - const struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
    -
    - if (skb->protocol == htons(ETH_P_CAN)) {
    - if (unlikely(skb->len != CAN_MTU ||
    - cfd->len > CAN_MAX_DLEN))
    - goto inval_skb;
    - } else if (skb->protocol == htons(ETH_P_CANFD)) {
    - if (unlikely(skb->len != CANFD_MTU ||
    - cfd->len > CANFD_MAX_DLEN))
    - goto inval_skb;
    - } else
    - goto inval_skb;
    -
    - if (!can_skb_headroom_valid(dev, skb))
    - goto inval_skb;
    -
    - return false;
    -
    -inval_skb:
    - kfree_skb(skb);
    - dev->stats.tx_dropped++;
    - return true;
    -}
    -
    static inline bool can_is_canfd_skb(const struct sk_buff *skb)
    {
    /* the CAN specific type of skb is identified by its data length */
    --
    2.35.1
    \
     
     \ /
      Last update: 2022-05-13 16:25    [W:7.882 / U:0.104 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site