Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp2348059qtg; Wed, 22 Mar 2023 22:17:36 -0700 (PDT) X-Google-Smtp-Source: AK7set+ZsjxqAkgGOYPaP3nACaYvFG9WSQV08ODGU9xdIJXAQhFHpLUvN7ZCJ20Cz/uqJ8tp92vB X-Received: by 2002:a17:90b:4f48:b0:237:29b1:1893 with SMTP id pj8-20020a17090b4f4800b0023729b11893mr6222199pjb.46.1679548655741; Wed, 22 Mar 2023 22:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679548655; cv=none; d=google.com; s=arc-20160816; b=dqrCz5n6ANnlABGsUojS0qol+3zYlOGCpHHuI++VgK3FaU/YTHIACvnx8bagFmRrwN 4meZhnsLmyWNR51ofvdVXX4IIPVRZn54wfOTWXq1VArYQpJ2Ijb8tHOY4G5iJ++U0uLi GpJ0vAirVBsUlElss803o5ZHKLYSoyQE3qUnM61/tEPVXMSO0TFlU3GSNqKLJNs02cfJ ftIqf1Bh5UTtW0DX1/UvxE0IaUs0/XRUiJiGL6JL+EcuyXWCAomsICSAFUAjlPKq8+fQ errF3PIa6AerjJJhd4eMa2ye9+axopOwBgedGMBZ+JJlOSf3tz/k2u+zaiHCGFutN/GS 5pQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=LpIU9XcwrqJ0+O5M9NAndHnl7TY2o8/l2zt32Xf2HJs=; b=G5djFBUXpEcYBMt33IJpywV9Gc+5dWRnEENsBW871AnSVznD2gtE20JHoCuWNRzVss kIfTckFlslKO06X7I6A5kM0HEWVvMB0RZVeOr9JLf5e8j2tGTHSDYjCNUbmfXkCRFagW GB6+H7dwg7WLSr982vc5bQ7IqcVkQ904SieZxBspEqv96x1c61UVRopy+H/+gFQBHm5x MH6Zd7V/ZjSAI2A8cDgKifeFn3AzZAK29nn5pv4VF1dlWNkQV9cdHfXPzqKpRwDtv+iH Es3j+SG+aayaf7J39D+gKAbFczzp/Nms3oab2ENCgtiKApaSLaClVBo+qO0GMTMjql5V SelQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a17090b018200b0023f0bda978bsi832804pjs.49.2023.03.22.22.17.23; Wed, 22 Mar 2023 22:17:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbjCWFNA (ORCPT + 99 others); Thu, 23 Mar 2023 01:13:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbjCWFM5 (ORCPT ); Thu, 23 Mar 2023 01:12:57 -0400 Received: from mail.fintek.com.tw (mail.fintek.com.tw [59.120.186.242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0732F1EFC6; Wed, 22 Mar 2023 22:12:53 -0700 (PDT) Received: from vmMailSRV.fintek.com.tw ([192.168.1.1]) by mail.fintek.com.tw with ESMTP id 32N5BK2V014589; Thu, 23 Mar 2023 13:11:20 +0800 (+08) (envelope-from peter_hong@fintek.com.tw) Received: from [192.168.1.111] (192.168.1.111) by vmMailSRV.fintek.com.tw (192.168.1.1) with Microsoft SMTP Server id 14.3.498.0; Thu, 23 Mar 2023 13:11:20 +0800 Message-ID: Date: Thu, 23 Mar 2023 13:11:20 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH V2] can: usb: f81604: add Fintek F81604 support Content-Language: en-US To: Vincent MAILHOL CC: , , , , , , , , , , , , References: <20230321081152.26510-1-peter_hong@fintek.com.tw> From: Peter Hong In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [192.168.1.111] X-TM-AS-Product-Ver: SMEX-12.5.0.2055-9.0.1002-27520.000 X-TM-AS-Result: No-12.115600-8.000000-10 X-TMASE-MatchedRID: QfHZjzml1E//9O/B1c/Qy3UVR7WQKpLPC/ExpXrHizx6km1x+yMYzb4E LhML5UNkRMOrk8OCzo763zLdqQn7vdBUMX40Rzs4FWovz5bBLuaycrvYxo9Kp1kFotLUdLsqsmc +HzD5HmjrVITpd9hVjw3ukX1phG3AnpdzfoA7wedC4WIP7GtYLBgff28UuvIT9mqZiOfja88kKo BDEWGB+2ChicyzmckEYt5+J3IIlN5lJTodqNqEzs36paW7ZnFoyeUl7aCTy8hmimiikJEPRKPFj JEFr+olA6QGdvwfwZZ3M7/Jzxffcd0H8LFZNFG7bkV4e2xSge5F8NDAs67gVTiVFRh82bGNCo8h O50wCrYi0tLziQzeNT6Qrn3xh/cy X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--12.115600-8.000000 X-TMASE-Version: SMEX-12.5.0.2055-9.0.1002-27520.000 X-TM-SNTS-SMTP: AF440AECAECE3698103DAC244E9705E57134ED1A605F97D33B1C7BC8FCEDAE842000:8 X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: mail.fintek.com.tw 32N5BK2V014589 X-Spam-Status: No, score=-0.0 required=5.0 tests=NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vincent, Vincent MAILHOL 於 2023/3/21 下午 11:50 寫道: >> +static netdev_tx_t f81604_start_xmit(struct sk_buff *skb, >> + struct net_device *netdev) >> +{ >> + struct can_frame *cf = (struct can_frame *)skb->data; >> + struct f81604_port_priv *priv = netdev_priv(netdev); >> + struct net_device_stats *stats = &netdev->stats; >> + int status; >> + u8 *ptr; >> + u32 id; >> + >> + if (can_dropped_invalid_skb(netdev, skb)) >> + return NETDEV_TX_OK; >> + >> + netif_stop_queue(netdev); >> + >> + ptr = priv->bulk_write_buffer; >> + memset(ptr, 0, F81604_DATA_SIZE); >> + >> + ptr[0] = F81604_CMD_DATA; >> + ptr[1] = min_t(u8, cf->can_dlc & 0xf, 8); >> + >> + if (cf->can_id & CAN_EFF_FLAG) { >> + id = (cf->can_id & CAN_ERR_MASK) << 3; >> + ptr[1] |= F81604_EFF_BIT; >> + ptr[2] = (id >> 24) & 0xff; >> + ptr[3] = (id >> 16) & 0xff; >> + ptr[4] = (id >> 8) & 0xff; >> + ptr[5] = (id >> 0) & 0xff; >> + memcpy(&ptr[6], cf->data, ptr[1]); > Rather than manipulating an opaque u8 array, please declare a > structure with explicit names. I had try to declare a struct like below and refactoring code : struct f81604_bulk_data {     u8 cmd;     u8 dlc;     union {         struct {             u8 id1, id2;             u8 data[CAN_MAX_DLEN];         } sff;         struct {             u8 id1, id2, id3, id4;             u8 data[CAN_MAX_DLEN];         } eff;     }; } __attribute__((packed)); This struct can used in TX/RX bulk in/out. Is it ok? > +static int f81604_prepare_urbs(struct net_device *netdev) > +{ > + static const u8 bulk_in_addr[F81604_MAX_DEV] = { 0x82, 0x84 }; > + static const u8 bulk_out_addr[F81604_MAX_DEV] = { 0x01, 0x03 }; > + static const u8 int_in_addr[F81604_MAX_DEV] = { 0x81, 0x83 }; > + struct f81604_port_priv *priv = netdev_priv(netdev); > + int id = netdev->dev_id; > + int i; > + > + /* initialize to NULL for error recovery */ > + for (i = 0; i < F81604_MAX_RX_URBS; ++i) > + priv->read_urb[i] = NULL; > priv was allocated with devm_kzalloc() so it should already be zeroed, > right? What is the purpose of this loop? This operation due to following condition:     f81604_open() -> f81604_close() -> f81604_open() failed. We had used  devm_kzalloc() in f81604_probe(), so first f81604_open() all pointers are NULL. But after f81604_close() then f81604_open() second times, the URB pointers are not NULLed, it'll makes error on 2nd f81604_open() with fail. >> +/* Called by the usb core when driver is unloaded or device is removed */ >> +static void f81604_disconnect(struct usb_interface *intf) >> +{ >> + struct f81604_priv *priv = usb_get_intfdata(intf); >> + int i; >> + >> + for (i = 0; i < F81604_MAX_DEV; ++i) { >> + if (!priv->netdev[i]) >> + continue; >> + >> + unregister_netdev(priv->netdev[i]); >> + free_candev(priv->netdev[i]); >> + } > i> +} Is typo here? Thanks.