From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on archive.lwn.net X-Spam-Level: X-Spam-Status: No, score=-5.6 required=5.0 tests=DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by archive.lwn.net (Postfix) with ESMTP id 6C6307D072 for ; Wed, 30 May 2018 12:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752162AbeE3MUl (ORCPT ); Wed, 30 May 2018 08:20:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:53218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999AbeE3MUk (ORCPT ); Wed, 30 May 2018 08:20:40 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 857E420880; Wed, 30 May 2018 12:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527682840; bh=eZ3kFNL1isF7gxVaZDtfToDVdvovD/IDr5sisrDa0xw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Pqg6RiU7x/gyHjKjiga6b9UQHoBb6eBQHIosq2VAn9WEnnDY6hFnztU7VTX+IsRKL +JRsZOEZH2U6v65AtoHhNEUvbY+pYgDqJhZuE0YrObo1/aldYAIH4Db6l1xqCNBj9J esvQmQbeQD7oWz3h8EqJL0UFjTLRCklWeCMCfPYE= Date: Wed, 30 May 2018 14:20:19 +0200 From: Greg Kroah-Hartman To: Marcus Folkesson Cc: Andy Shevchenko , Jonathan Corbet , Felipe Balbi , "David S. Miller" , Mauro Carvalho Chehab , Andrew Morton , Randy Dunlap , Ruslan Bilovol , Thomas Gleixner , Kate Stewart , USB , Linux Documentation List , Linux Kernel Mailing List Subject: Re: [PATCH v3 1/3] usb: gadget: ccid: add support for USB CCID Gadget Device Message-ID: <20180530122019.GA28045@kroah.com> References: <20180529185021.13738-1-marcus.folkesson@gmail.com> <20180530112459.GB2939@gmail.com> <20180530113026.GA20775@kroah.com> <20180530121357.GD2939@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180530121357.GD2939@gmail.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Wed, May 30, 2018 at 02:13:57PM +0200, Marcus Folkesson wrote: > Hi Greg, > > On Wed, May 30, 2018 at 01:30:26PM +0200, Greg Kroah-Hartman wrote: > > On Wed, May 30, 2018 at 01:24:59PM +0200, Marcus Folkesson wrote: > > > Hi Andy, > > > > > > Thank you for your comments! > > > Many good catches here! > > > > > > On Wed, May 30, 2018 at 03:55:39AM +0300, Andy Shevchenko wrote: > > > > On Tue, May 29, 2018 at 9:50 PM, Marcus Folkesson > > > > wrote: > > > > > Chip Card Interface Device (CCID) protocol is a USB protocol that > > > > > allows a smartcard device to be connected to a computer via a card > > > > > reader using a standard USB interface, without the need for each manufacturer > > > > > of smartcards to provide its own reader or protocol. > > > > > > > > > > This gadget driver makes Linux show up as a CCID device to the host and let a > > > > > userspace daemon act as the smartcard. > > > > > > > > > > This is useful when the Linux gadget itself should act as a cryptographic > > > > > device or forward APDUs to an embedded smartcard device. > > > > > > > > > + * Copyright (C) 2018 Marcus Folkesson > > > > > > > > > + * > > > > > > > > Redundant line > > > > > > > > > > Yep > > > > > > > > +static DEFINE_IDA(ccidg_ida); > > > > > > > > Where is it destroyed? > > > > > > Hm, I'm not sure it needs to be destroyed. From lib/idr.c: > > > > > > * You can also use ida_get_new_above() if you need an ID to be allocated > > > * above a particular number. ida_destroy() can be used to dispose of an > > > * IDA without needing to free the individual IDs in it. You can use > > > * ida_is_empty() to find out whether the IDA has any IDs currently allocated. > > > > > > > > > An empty ccidg_ida is the indication that we should clean up our > > > mess: > > > > > > static void ccidg_free_inst(struct usb_function_instance *f) > > > ... > > > if (ida_is_empty(&ccidg_ida)) > > > ccidg_cleanup(); > > > > > > If the IDA is empty, should I call ida_destroy() anyway? > > > Other similiar drivers does not seems to do that. > > > > > > I must say that I'm not very familiar with the IDA API. > > > > When your module is removed, you need to clean up any remaining memory > > that the ida used. It's not obvious at all, and is a pain as you would > > think that if you statically allocate one, like you have here, it would > > not be needed. You need to just call: > > ida_destroy(&ccidg_ida); > > in your module exit function. > > > > Hope this helps, > > Thank you for making it clear. > > Maybe I should use > #define DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ > > instead of > #define DECLARE_USB_FUNCTION_INIT(_name, _inst_alloc, _func_alloc) \ > > and provide my own module_init/module_exit functions then? Probably, yes. -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Subject: [v3,1/3] usb: gadget: ccid: add support for USB CCID Gadget Device From: Greg Kroah-Hartman Message-Id: <20180530122019.GA28045@kroah.com> Date: Wed, 30 May 2018 14:20:19 +0200 To: Marcus Folkesson Cc: Andy Shevchenko , Jonathan Corbet , Felipe Balbi , "David S. Miller" , Mauro Carvalho Chehab , Andrew Morton , Randy Dunlap , Ruslan Bilovol , Thomas Gleixner , Kate Stewart , USB , Linux Documentation List , Linux Kernel Mailing List List-ID: T24gV2VkLCBNYXkgMzAsIDIwMTggYXQgMDI6MTM6NTdQTSArMDIwMCwgTWFyY3VzIEZvbGtlc3Nv biB3cm90ZToKPiBIaSBHcmVn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Ao+ID4gbm90IGJlIG5lZWRlZC4gIFlvdSBu ZWVkIHRvIGp1c3QgY2FsbDoKPiA+IAlpZGFfZGVzdHJveSgmY2NpZGdfaWRhKTsKPiA+IGluIHlv dXIgbW9kdWxlIGV4aXQgZnVuY3Rpb24uCj4gPiAKPiA+IEhvcGUgdGhpcyBoZWxwcywKPiAKPiBU aGFuayB5b3UgZm9yIG1ha2luZyBpdCBjbGVhci4KPiAKPiBNYXliZSBJIHNob3VsZCB1c2UKPiAj ZGVmaW5lIERFQ0xBUkVfVVNCX0ZVTkNUSU9OKF9uYW1lLCBfaW5zdF9hbGxvYywgX2Z1bmNfYWxs b2MpCQlcCj4gCj4gaW5zdGVhZCBvZiAKPiAjZGVmaW5lIERFQ0xBUkVfVVNCX0ZVTkNUSU9OX0lO SVQoX25hbWUsIF9pbnN0X2FsbG9jLCBfZnVuY19hbGxvYykJXAo+IAo+IGFuZCBwcm92aWRlIG15 IG93biBtb2R1bGVfaW5pdC9tb2R1bGVfZXhpdCBmdW5jdGlvbnMgdGhlbj8KClByb2JhYmx5LCB5 ZXMuCi0tLQpUbyB1bnN1YnNjcmliZSBmcm9tIHRoaXMgbGlzdDogc2VuZCB0aGUgbGluZSAidW5z dWJzY3JpYmUgbGludXgtdXNiIiBpbgp0aGUgYm9keSBvZiBhIG1lc3NhZ2UgdG8gbWFqb3Jkb21v QHZnZXIua2VybmVsLm9yZwpNb3JlIG1ham9yZG9tbyBpbmZvIGF0ICBodHRwOi8vdmdlci5rZXJu ZWwub3JnL21ham9yZG9tby1pbmZvLmh0bWwK From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753079AbeE3MUo (ORCPT ); Wed, 30 May 2018 08:20:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:53218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999AbeE3MUk (ORCPT ); Wed, 30 May 2018 08:20:40 -0400 Date: Wed, 30 May 2018 14:20:19 +0200 From: Greg Kroah-Hartman To: Marcus Folkesson Cc: Andy Shevchenko , Jonathan Corbet , Felipe Balbi , "David S. Miller" , Mauro Carvalho Chehab , Andrew Morton , Randy Dunlap , Ruslan Bilovol , Thomas Gleixner , Kate Stewart , USB , Linux Documentation List , Linux Kernel Mailing List Subject: Re: [PATCH v3 1/3] usb: gadget: ccid: add support for USB CCID Gadget Device Message-ID: <20180530122019.GA28045@kroah.com> References: <20180529185021.13738-1-marcus.folkesson@gmail.com> <20180530112459.GB2939@gmail.com> <20180530113026.GA20775@kroah.com> <20180530121357.GD2939@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180530121357.GD2939@gmail.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 30, 2018 at 02:13:57PM +0200, Marcus Folkesson wrote: > Hi Greg, > > On Wed, May 30, 2018 at 01:30:26PM +0200, Greg Kroah-Hartman wrote: > > On Wed, May 30, 2018 at 01:24:59PM +0200, Marcus Folkesson wrote: > > > Hi Andy, > > > > > > Thank you for your comments! > > > Many good catches here! > > > > > > On Wed, May 30, 2018 at 03:55:39AM +0300, Andy Shevchenko wrote: > > > > On Tue, May 29, 2018 at 9:50 PM, Marcus Folkesson > > > > wrote: > > > > > Chip Card Interface Device (CCID) protocol is a USB protocol that > > > > > allows a smartcard device to be connected to a computer via a card > > > > > reader using a standard USB interface, without the need for each manufacturer > > > > > of smartcards to provide its own reader or protocol. > > > > > > > > > > This gadget driver makes Linux show up as a CCID device to the host and let a > > > > > userspace daemon act as the smartcard. > > > > > > > > > > This is useful when the Linux gadget itself should act as a cryptographic > > > > > device or forward APDUs to an embedded smartcard device. > > > > > > > > > + * Copyright (C) 2018 Marcus Folkesson > > > > > > > > > + * > > > > > > > > Redundant line > > > > > > > > > > Yep > > > > > > > > +static DEFINE_IDA(ccidg_ida); > > > > > > > > Where is it destroyed? > > > > > > Hm, I'm not sure it needs to be destroyed. From lib/idr.c: > > > > > > * You can also use ida_get_new_above() if you need an ID to be allocated > > > * above a particular number. ida_destroy() can be used to dispose of an > > > * IDA without needing to free the individual IDs in it. You can use > > > * ida_is_empty() to find out whether the IDA has any IDs currently allocated. > > > > > > > > > An empty ccidg_ida is the indication that we should clean up our > > > mess: > > > > > > static void ccidg_free_inst(struct usb_function_instance *f) > > > ... > > > if (ida_is_empty(&ccidg_ida)) > > > ccidg_cleanup(); > > > > > > If the IDA is empty, should I call ida_destroy() anyway? > > > Other similiar drivers does not seems to do that. > > > > > > I must say that I'm not very familiar with the IDA API. > > > > When your module is removed, you need to clean up any remaining memory > > that the ida used. It's not obvious at all, and is a pain as you would > > think that if you statically allocate one, like you have here, it would > > not be needed. You need to just call: > > ida_destroy(&ccidg_ida); > > in your module exit function. > > > > Hope this helps, > > Thank you for making it clear. > > Maybe I should use > #define DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ > > instead of > #define DECLARE_USB_FUNCTION_INIT(_name, _inst_alloc, _func_alloc) \ > > and provide my own module_init/module_exit functions then? Probably, yes.