Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751714AbaL3Piu (ORCPT ); Tue, 30 Dec 2014 10:38:50 -0500 Received: from mail-wi0-f172.google.com ([209.85.212.172]:58685 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751310AbaL3Pis (ORCPT ); Tue, 30 Dec 2014 10:38:48 -0500 Date: Tue, 30 Dec 2014 10:33:26 -0500 From: "Ahmed S. Darwish" To: Olivier Sobrie Cc: Oliver Hartkopp , Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Paul Gortmaker , Linux-CAN , netdev , LKML Subject: Re: [PATCH] can: kvaser_usb: Add support for the Usbcan-II family Message-ID: <20141230153326.GA3798@linux> References: <20141223154654.GB6460@vivalin-002> <20141223155311.GA5997@vivalin-002> <20141224150417.GB5707@vivalin-002> <20141228215134.GA2548@thinkoso.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141228215134.GA2548@thinkoso.home> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 28, 2014 at 10:51:34PM +0100, Olivier Sobrie wrote: [...] > > > > > > > > + if (LEAF_PRODUCT_ID(id->idProduct)) { > > > > + dev->family = KVASER_LEAF; > > > > + dev->max_channels = LEAF_MAX_NET_DEVICES; > > > > + } else if (USBCAN_PRODUCT_ID(id->idProduct)) { > > > > + dev->family = KVASER_USBCAN; > > > > + dev->max_channels = USBCAN_MAX_NET_DEVICES; > > > > + } else { > > > > + dev_err(&intf->dev, "Product ID (%d) does not belong to any " > > > > + "known Kvaser USB family", id->idProduct); > > > > + return -ENODEV; > > > > + } > > > > + > > > > > > Is it really required to keep max_channels in the kvaser_usb structure? > > > If I looked correctly, you use this variable as a replacement for > > > MAX_NET_DEVICES in the code and MAX_NET_DEVICES is only used in probe > > > and disconnect functions. I think it can even be replaced by nchannels > > > in the disconnect path. So I also think that it don't need to be in the > > > kvaser_usb structure. > > > > > > > hmmm.. given the current state of error arbitration explained > > above, where I cannot accept a dev->nchannels > 2, I guess we > > have two options: > > > > a) Remove max_channels, and hardcode the channels count > > correctness logic as follows: > > > > dev->nchannels = msg.u.cardinfo.nchannels; > > if ((dev->family == USBCAN && dev->nchannels > USBCAN_MAX_NET_DEVICES) > > || (dev->family == LEAF && dev->nchannels > LEAF_MAX_NET_DEVICES)) > > return -EINVAL > > > > b) Leave max_channels in 'struct kvaser_usb' as is. > > > > I personally prefer the solution at 'b)' but I can do it as > > in 'a)' if you prefer :-) > > Keeping max_channels in the kvaser_usb structure is useless because it > is only used in one function that is called in the probe function. > > I would prefer to have: > if (dev->nchannels > MAX_NET_DEVICES) > return -EINVAL > > if ((dev->family == USBCAN) && > (dev->nchannels > MAX_USBCAN_NET_DEVICES)) > return -EINVAL > > You can remove LEAF_MAX_NET_DEVICES which is not used, keep > MAX_NET_DEVICES equals to 3 and remove the MAX() macro. > The test specific to the USBCAN family can eventually be moved in the > kvaser_usb_probe() function. > Quite nice, will do it that way in v3. Regards, Darwish -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/