Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2167741ybi; Thu, 4 Jul 2019 06:15:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyeSaMvy5KvgM2RmlUu5mV/VH28mbACo3MXx+NGuSE4dXBbDWItmv6Y3RekC2jQKskeREEv X-Received: by 2002:a17:902:b186:: with SMTP id s6mr49223819plr.343.1562246107720; Thu, 04 Jul 2019 06:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562246107; cv=none; d=google.com; s=arc-20160816; b=UwdDFTUlXbolIKk1dIuZJjRP1RVANjGa2TlP50gsGqS6YuQ+I1WvsLKc0u9TEpzvAh UqhjWn5PuucsPUBktnS/v85rWrM5zVMlUhzjt5XnCz9WJgV06yAu+FnaBYKimfzac43o MUlmqC6RJFZ99eOqeFry0Ga3c/kRf29fN7721++uhlWo2ck0numPLDBf29S/ch7PAczR MM2MkcKTJ668iP6FSHaXbTaPSIlYDh0pmcbqAzwzvDdoKSvZrXxIZQNLyroZ17Zzha6v SdLNwtaOr9u1a0E6+aLf9whg02TGA/GX9r5Lix6mWG+/9e9xjJ8MlGUHWmPUbcsBH/IZ h5RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=20IJcBWzmnFCKjBAaicnv9Vc8ZHVCUlkxY6/DEFnJFU=; b=zqXTJZuNbsiVg4mRmSlY/4TE1EiUVKBMcP7bgT3AMMoSVjUrcANk5DP6GXaykH3faE SD7ByFvgaaDU75ZRt00NobdV2r4+moDzDgCgrz7U1Kdk1q2XIc4LkTP6t8fcSRCCEVhb LSUp8tGrWAokZ39RF3ncKnXqC1fxt5qx9b+tGVdh68JpxhpVsQNrAOM2A31zvg/mVnRz q7of0NP4JsYEs4iTwSP3KyMeL0EBbcvuvUYj/5hX+17hWLEIxS9fClUOZSH0wGHrUtM3 ytSN8qA9TvZ+yjEWTXMDRPJbsHRxEJQXHS8uN58DoFduUU5WVt97R0+aH5WaViuqVDly fUVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si5286726pgp.343.2019.07.04.06.14.52; Thu, 04 Jul 2019 06:15:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbfGDNNE (ORCPT + 99 others); Thu, 4 Jul 2019 09:13:04 -0400 Received: from mx2.suse.de ([195.135.220.15]:43744 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726994AbfGDNND (ORCPT ); Thu, 4 Jul 2019 09:13:03 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0FE18B114; Thu, 4 Jul 2019 13:13:02 +0000 (UTC) Date: Thu, 04 Jul 2019 15:13:01 +0200 Message-ID: From: Takashi Iwai To: "Fuqian Huang" Cc: , "Jaroslav Kysela" , "Takashi Iwai" , Subject: Re: [PATCH v2 33/35] sound/pci: Use kmemdup rather than duplicating its implementation In-Reply-To: <20190703163210.983-1-huangfq.daxian@gmail.com> References: <20190703163210.983-1-huangfq.daxian@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 03 Jul 2019 18:32:10 +0200, Fuqian Huang wrote: > > kmemdup is introduced to duplicate a region of memory in a neat way. > Rather than kmalloc/kzalloc + memcpy, which the programmer needs to > write the size twice (sometimes lead to mistakes), kmemdup improves > readability, leads to smaller code and also reduce the chances of mistakes. > Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy. > > Signed-off-by: Fuqian Huang > --- > Changes in v2: > - Fix a typo in commit message (memset -> memcpy) > > sound/pci/echoaudio/echoaudio.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c > index b612a536a5a1..35bd3e7c8ce1 100644 > --- a/sound/pci/echoaudio/echoaudio.c > +++ b/sound/pci/echoaudio/echoaudio.c > @@ -2189,11 +2189,10 @@ static int snd_echo_resume(struct device *dev) > u32 pipe_alloc_mask; > int err; > > - commpage_bak = kmalloc(sizeof(*commpage), GFP_KERNEL); > + commpage_bak = kmemdup(commpage, sizeof(*commpage), GFP_KERNEL); > if (commpage_bak == NULL) > return -ENOMEM; > commpage = chip->comm_page; > - memcpy(commpage_bak, commpage, sizeof(*commpage)); > > err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); > if (err < 0) { The patch is obviously wrong and leads to a crash. See that the assignment of the source address is done after the kmalloc() call but before memcpy(). With kmemdup(), this will be screwed up. This error could be caught easily by just compiling the kernel, too. Please do at least the proper build test at the next time. thanks, Takashi