From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756365AbcHDGjk (ORCPT ); Thu, 4 Aug 2016 02:39:40 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:34934 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750819AbcHDGjj (ORCPT ); Thu, 4 Aug 2016 02:39:39 -0400 Subject: Re: [PATCH] usb:serial: Add Fintek F81532/534 driver To: One Thousand Gnomes References: <1464658417-2689-1-git-send-email-hpeter+linux_kernel@gmail.com> <20160729134802.3bdbfe84@lxorguk.ukuu.org.uk> Cc: johan@kernel.org, gregkh@linuxfoundation.org, tom_tsai@fintek.com.tw, peter_hong@fintek.com.tw, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Ji-Ze Hong (Peter Hong)" From: "Ji-Ze Hong (Peter Hong)" Message-ID: Date: Thu, 4 Aug 2016 14:25:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160729134802.3bdbfe84@lxorguk.ukuu.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alan, One Thousand Gnomes 於 2016/7/29 下午 08:48 寫道: > O >> +static int f81534_set_normal_register(struct usb_device *dev, u16 reg, u8 data) >> +{ >> + size_t count = F81534_USB_MAX_RETRY; >> + int status; >> + u8 *tmp; >> + >> + tmp = kmalloc(sizeof(u8), GFP_KERNEL); >> + if (!tmp) >> + return -ENOMEM; > > You end up doing huge numbers of tiny allocation and frees in some of the > code paths. I think it would be better to allocate them at a higher level > as they are not that cheap on CPU time. > >> +static int f81534_read_data(struct usb_serial *usbserial, u32 address, >> + size_t size, unsigned char *buf) >> +{ > > Is a particularly good example - you do 4 mallocs plus two per byte of > data. > I'll re-factor the newest V9 patch with your suggestion. To malloc a byte within usb_serial privates, and make a mutex to protect it. I'll send it as V10 when I tested it. Thanks for your suggestion. -- With Best Regards, Peter Hong