Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2932178iog; Mon, 20 Jun 2022 07:45:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sTqnAHeCFzIQT4SYauCvh+tRSKY9whte7pjHNV3I0Kw/t/bEc2uf+iIC75GkC76X4ft0zE X-Received: by 2002:a65:6a9a:0:b0:40c:a106:ed84 with SMTP id q26-20020a656a9a000000b0040ca106ed84mr7307206pgu.417.1655736328805; Mon, 20 Jun 2022 07:45:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736328; cv=none; d=google.com; s=arc-20160816; b=oJH11P6hPewdo02nM5yT2IQonw61E2PTa7ZdApHU6pQn4zGfGJPU1X1PP3pKEIYz/H Fp7KznWEsNP5G/waOnxy5vNpS7eGgSzMqQcytWaZF31mWjDly6fs27UOi+XZHCejWXvg n9/Hvb3SmJ8azd6eEmsihJU4chfobOnpB9mlZyjkkgOWVa0W9lYZX/aGrj3JcaECVGpC rPc8fkRFzia7j46VtXrSrjyQ+DguvjClOvkVKdrdRKBYitMMWvOzQAkFOM9NwcoxDDoC Q1k6UbslL7y/PgilNMgiEJjjcAIDvS2o/QTX078e/9NX70Dat7oCEnn6R5cTqaYYTUKW O9Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=u4K1SGXKg+JKNZIS1vSP4VA3yvqHhxOuBpn61GGBCRI=; b=lmn8kiBHhrHNENJjGOdjm/uFVsWmiMmqTWl+tzqkrkAErEeYFigP/Px5rgWkTozoso N4sUPhz78PzEwfZZ7PId9fFYwR1MJp1x2+bU/wnX+pVCXZw5pGVdsGf5SerHTX99naYh uuVkz+DpwvtzpyxxXWQBgnGgNT8YvDOHyVSo1GPJLPh8IU9FqsEyVuT3UQBPgicdXVuO JXO7/zXWt613ZQNqtz75mJiQpXUSs3lF3az8lVp6OD6Oq7H89R38vA0toKHlaCGq5Wq9 2P8VUE6qdpva6TS8AFRacojkKBlWwo4Oc8xU090kqTY1o+5CWW2qK8u7nzY31xQtNpRV 4McA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DzBJYmas; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a62640b000000b0051e77ab003esi9012406pfb.68.2022.06.20.07.45.16; Mon, 20 Jun 2022 07:45:28 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DzBJYmas; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346004AbiFTNbJ (ORCPT + 99 others); Mon, 20 Jun 2022 09:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346757AbiFTN3R (ORCPT ); Mon, 20 Jun 2022 09:29:17 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 079D3248F3; Mon, 20 Jun 2022 06:11:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id C0EF5CE139F; Mon, 20 Jun 2022 13:10:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC825C3411C; Mon, 20 Jun 2022 13:10:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655730653; bh=SHVwJLEk2tnmicNGaRD3YPQJdxFUin99Ol3gEng/YzA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DzBJYmasWqnspP8jyZlLQwdZh+WpKwfIQaHEJQohLSkOnCxyJTrIni3XGZkn2x7Yl zRqmC7/woIw1ThSGqggImr1d7rRVupXKZAe/RnXH5lbzMkGQtVPE/bsNoGL6DwZ4t2 okIXjHqB3novCwABI2il9fXgs1Ks7ai4feFwpW80Buumn0nkFY0vKXoBSaLAgno6PD NhnAsvAZPb8XJd3km+w/ZY7YJFo9pRk9A4dIzQdjfQbX9DN9ypUoAokdEG72ENz0PX XAxd0W/qEtTJoI1+zr+Do3FQARkLuecRexLZJjn522xf575e3CmZFTz7KBuyBpqDId lL1j9CENZP/jw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1o3HB3-0000z6-3O; Mon, 20 Jun 2022 15:10:49 +0200 Date: Mon, 20 Jun 2022 15:10:49 +0200 From: Johan Hovold To: Slark Xiao Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] USB: serial: use kmemdup instead of kmalloc + memcpy Message-ID: References: <20220620105939.5128-1-slark_xiao@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220620105939.5128-1-slark_xiao@163.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Mon, Jun 20, 2022 at 06:59:39PM +0800, Slark Xiao wrote: > For code neat purpose, we can use kmemdup to replace > kmalloc + memcpy. > > Signed-off-by: Slark Xiao > --- > drivers/usb/serial/opticon.c | 4 +--- > drivers/usb/serial/sierra.c | 4 +--- > 2 files changed, 2 insertions(+), 6 deletions(-) > > diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c > index aed28c35caff..bca6766a63e6 100644 > --- a/drivers/usb/serial/opticon.c > +++ b/drivers/usb/serial/opticon.c > @@ -208,7 +208,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, > priv->outstanding_bytes += count; > spin_unlock_irqrestore(&priv->lock, flags); > > - buffer = kmalloc(count, GFP_ATOMIC); > + buffer = kmemdup(buf, count, GFP_ATOMIC); > if (!buffer) > goto error_no_buffer; > > @@ -216,8 +216,6 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, > if (!urb) > goto error_no_urb; > > - memcpy(buffer, buf, count); > - > usb_serial_debug_data(&port->dev, __func__, count, buffer); > > /* The connected devices do not have a bulk write endpoint, Looks like we have the same pattern also in garmin_write_bulk(). Care to include that one as well? Johan