Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3738628rwl; Sun, 9 Apr 2023 23:35:40 -0700 (PDT) X-Google-Smtp-Source: AKy350aN1S3be+Pfy22S8dYSEp8cPKqGP5bJ0p39gz5/2cncrMTK8NZmHo201X50AjuomNaZznH9 X-Received: by 2002:a17:90b:3807:b0:23e:2b3c:d4bf with SMTP id mq7-20020a17090b380700b0023e2b3cd4bfmr8768729pjb.45.1681108540265; Sun, 09 Apr 2023 23:35:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681108540; cv=none; d=google.com; s=arc-20160816; b=A1TQKq6HQi7c2NmAXEDawVVstDCLDivD4yEf74j0VuoXKVqHH/60TaY4qu0M02f7Qc uAb3rRP0IEcZOJL2P3x0dw4aBa/jc86x7BIvxrczMdL5dCdX8w0Qv/3lUcTJTE5fgeDM 9k4EhU6yN/6RE08aB2Xy0d6fnbU/qKkXu8bGp+MRCRqwf0CfspH1WZf9PH4RnFTGBaRx gMBsfKtq4gE1WxdhY5IFVe0BU2B6igTkUhARCc0M8LsVKGKp6za2H6hE8SXd6tSZ/aEc YQiO7YIZ9ZceKk76BcoyoZcREPM/+27vamhjBRTA+NlgmZ7mVXMrLuBtJOfcI5kgw96l EHrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=vT+CXyLXm1K/dpMBOsgp7VrtkYi/0fSzaib6SrkonPs=; b=HXpMdKf5DopHsHRScrT+RNdGrdvBdUnlUAmw9K4l7GSyvHwHkwu2o7Y8C1UZGdYGSv q1v2AgtmLz/20pwDsYfWuDyMEKPIdGOBbNzhqtrA4MbmYDDi34toRBNDuBJQ97Iw0HKC 2pie5qOKW+V0CwPE7I8B9ie6bXb8P+DcDTcR2VBuM28Kv8IcdOtcQRcpweVCjmQv+uzt 1Lxf3xI4PzmkA/OVBb+HSQ6EHuAw5vnokXPF5LnlG6Xyima9aQoadkrPgS/Dd4e5/hwM 7szeeGNUpaiy5tPILd2okt1wfPTwQ4pTZSHob/1Y8qIU+Q7zkBhKx7G616hpkYrYUgbz +dcQ== 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 l10-20020a17090a660a00b002465d98f18csi7177429pjj.170.2023.04.09.23.35.26; Sun, 09 Apr 2023 23:35:40 -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 S229663AbjDJG1C convert rfc822-to-8bit (ORCPT + 99 others); Mon, 10 Apr 2023 02:27:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbjDJG1B (ORCPT ); Mon, 10 Apr 2023 02:27:01 -0400 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBC2E40DF; Sun, 9 Apr 2023 23:26:56 -0700 (PDT) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6324adf8c69so367514b3a.3; Sun, 09 Apr 2023 23:26:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681108016; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1o4Fm/zMjwT/KOOu5Qq10NSwgAuEG/lxaflNYKbr+9w=; b=pWT7Vh09qPe8AfjSLiS1UkvPJI+TMrHgwiENafGyXGFvzpDf1qmKdCYFFOXqgfYoMI MVOJg8TgOsJ4MhoFneJjYQGsN2OxExdQqupB/OgO7Mo8PcLbo92cCxp8vToapOki/vCG rqtYl0veoZcJ+553xGSWo3qPVK/ReR1zNL8HbN+7pe2WDcsZ9Mg3Sl2irJiYZX0DV0I2 CKCxWrqQFkRaV7LSnbEm19hcqJijpMB3vMQgV4NQWDGFbCaIMwep2ZrlzGa53dtAPWdL cBHRCwBxbDhXoQOnAbAAg0tlD9xbKMOa4Ksm2MvElhUMBQa42dNd8wNHulNH3WYXjh1J 7u2w== X-Gm-Message-State: AAQBX9eERvdng+iseaEnR6bE2/uZfiLqbxEh+1CVZoNxRkndRTpiyKxi BFh9R7KTXRV45UJNwYObHHVg5ihfHCiYjuLjR50= X-Received: by 2002:a05:6a00:2182:b0:628:123c:99be with SMTP id h2-20020a056a00218200b00628123c99bemr4386385pfi.2.1681108016068; Sun, 09 Apr 2023 23:26:56 -0700 (PDT) MIME-Version: 1.0 References: <20230327051048.11589-1-peter_hong@fintek.com.tw> <5bdee736-7868-81c3-e63f-a28787bd0007@fintek.com.tw> <8f43fc07-39b1-4b1b-9dc6-257eb00c3a81@fintek.com.tw> <7e9c01da-74be-3d8d-bb0c-d90935d82081@fintek.com.tw> In-Reply-To: <7e9c01da-74be-3d8d-bb0c-d90935d82081@fintek.com.tw> From: Vincent MAILHOL Date: Mon, 10 Apr 2023 15:26:44 +0900 Message-ID: Subject: Re: [PATCH V3] can: usb: f81604: add Fintek F81604 support To: Peter Hong Cc: wg@grandegger.com, mkl@pengutronix.de, michal.swiatkowski@linux.intel.com, Steen.Hegelund@microchip.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, frank.jungclaus@esd.eu, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, hpeter+linux_kernel@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Peter, On Mon. 10 Apr 2023 at 14:52, Peter Hong wrote: > Hi Vincent, > > Vincent MAILHOL 於 2023/3/30 下午 09:11 寫道: > > Hmm, I am still not a fan of setting a mutex for a single concurrency > > issue which can only happen during probing. > > > > What about this: > > > > static int __f81604_set_termination(struct net_device *netdev, u16 term) > > { > > struct f81604_port_priv *port_priv = netdev_priv(netdev); > > u8 mask, data = 0; > > > > if (netdev->dev_id == 0) > > mask = F81604_CAN0_TERM; > > else > > mask = F81604_CAN1_TERM; > > > > if (term == F81604_TERMINATION_ENABLED) > > data = mask; > > > > return f81604_mask_set_register(port_priv->dev, F81604_TERMINATOR_REG, > > mask, data); > > } > > > > static int f81604_set_termination(struct net_device *netdev, u16 term) > > { > > ASSERT_RTNL(); > > > > return __f81604_set_termination(struct net_device *netdev, u16 term); > > } > > > > static int f81604_init_termination(struct f81604_priv *priv) > > { > > int i, ret; > > > > for (i = 0; i < ARRAY_SIZE(f81604_priv->netdev); i++) { > > ret = __f81604_set_termination(f81604_priv->netdev[i], > > F81604_TERMINATION_DISABLED); > > if (ret) > > return ret; > > } > > } > > > > static int f81604_probe(struct usb_interface *intf, > > const struct usb_device_id *id) > > { > > /* ... */ > > > > err = f81604_init_termination(priv); > > if (err) > > goto failure_cleanup; > > > > for (i = 0; i < ARRAY_SIZE(f81604_priv->netdev); i++) { > > /* ... */ > > } > > > > /* ... */ > > } > > > > Initialise all resistors with __f81604_set_termination() in probe() > > before registering any network device. Use f81604_set_termination() > > which has the lock assert elsewhere. > > The f81604_set_termination() will transform into the following code: > > static int f81604_write(struct usb_device *dev, u16 reg, u8 data); > static int f81604_read(struct usb_device *dev, u16 reg, u8 *data); > static int f81604_update_bits(struct usb_device *dev, u16 reg, u8 mask, > u8 data); > > static int __f81604_set_termination(struct usb_device *dev, int idx, u16 > term) > { > u8 mask, data = 0; > > if (idx == 0) > mask = F81604_CAN0_TERM; > else > mask = F81604_CAN1_TERM; > > if (term) > data = mask; > > return f81604_update_bits(dev, F81604_TERMINATOR_REG, mask, data); > } > > static int f81604_set_termination(struct net_device *netdev, u16 term) > { > struct f81604_port_priv *port_priv = netdev_priv(netdev); > struct f81604_priv *priv; > > ASSERT_RTNL(); > > priv = usb_get_intfdata(port_priv->intf); ^^^^ Why do you need priv here? I do not see it used in the next line. > return __f81604_set_termination(port_priv->dev, netdev->dev_id, term); > } > > and also due to f81604_write() / f81604_read() / f81604_update_bits() > may use > in f81604_probe() without port private data, so we'll change their first > parameter > from "struct f81604_port_priv *priv" to "struct usb_device *dev". Is it OK ? Right now, it is hard to visualize the final result. Please send what you think is the best and we will review. > > Also, looking at your probe() function, in label clean_candev:, if the > > second can channel fails its initialization, you do not clean the > > first can channel. I suggest adding a f81604_init_netdev() and > > handling the netdev issue and cleanup in that function. > > When the second can channel failed its initialization, the label > "clean_candev" will > clear second "netdev" object and the first "netdev" will cleanup in > f81604_disconnect(). > > Could I remain this section of code ? Oh! I was not aware that disconnect() would be called on a failed probe. Overall, I prefer the use of subfunctions because it makes it easier to understand the logic, especially for the cleanup after failure. Let's say that it is acceptable as-is. OK to keep.