Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1106224ybi; Wed, 3 Jul 2019 09:35:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsKOUnwKZ4QE3zvoI0FQCQg+Z2tA6no6OzzdJ3mXQtlz9Ls3Ab8Br/7pPAHD4iwlgghk7B X-Received: by 2002:a17:90a:d817:: with SMTP id a23mr13606948pjv.54.1562171717950; Wed, 03 Jul 2019 09:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562171717; cv=none; d=google.com; s=arc-20160816; b=TLwfuSJTu840L1FJz/0Q8FvS1AxYiu8fNy+XKft0stGNOrNqN9IKk8RDOhaRRsiWPi iVY/Bvyv3Z7CGqkMvvYKpeUlhtGNbdwCkGEPUamhQ1fqp17JhaCxkCbygp8gEJqci1kk A5eHgI43Pditbnawh3+nNAqWoWqEHvYEpXz/TXZlXOP92KzqiiyBdrSFsA0zUhr/wboq V5zan6/NBcNcBWxhtgHmz7bXBkci6sIXpO6PNrdzmnMduwabueK+5e6wWIL7OUHgkVd8 ewXXSAbvmuFNy1XzqdU5bjkuHOreYwW84PPjqVWAacofwvjJoeF0TVaK3yFgfT7IyG/b ofAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature; bh=l0364bIasEWF4u6q6PoJgdA0dWNvfPQBCr9kLEyFzmc=; b=xLZIK2UlLL9OFgZyzaeMM3j/p4fw9uUAgGzay15t//XhTv2gRY7VSXpVf3xQpQT4B2 LaFh3czEMUQvarUfop9bZldiqtlTXtWsPr0akiw/ZG0BnTSIkpQbRnfsv+ksh9FgPkV7 av4cGzbP+f5yxoM0UE2d8aF1SyIFWEWXrD7Hrhf/z2Sbdpnrtg7yoeE/VTtiR1KMOHEb sIo5+W6RVLb7576dhMDAQTPw/wmpqYRq1CF/G27dxwnah5QsJVQWq2nZS8fh9MQSpbNS DsHI2OUoMgGGXKwX9b03QHokCw3CmaDuZtA6imz9tq8HSVwS9BnI3rn6j7i6C5MCB7o0 NJLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="A3/1i6PF"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z142si2723626pfc.128.2019.07.03.09.35.03; Wed, 03 Jul 2019 09:35:17 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b="A3/1i6PF"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727257AbfGCQcf (ORCPT + 99 others); Wed, 3 Jul 2019 12:32:35 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38062 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726915AbfGCQcf (ORCPT ); Wed, 3 Jul 2019 12:32:35 -0400 Received: by mail-pg1-f196.google.com with SMTP id z75so1513916pgz.5 for ; Wed, 03 Jul 2019 09:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=l0364bIasEWF4u6q6PoJgdA0dWNvfPQBCr9kLEyFzmc=; b=A3/1i6PFKv8gEafTpu+DrcOtTvtUVbk5N0FhU3sAIRCeitnnDZl/16Vgwj94zhFZRw sloUEURPQeMMX4uVZq7nUxbncgxJJDxnsQEx5LGUxopH1IJ5oNMFuliVpw+YwjuTn0Hl hY7MHjdi8wl8/WsuuDcyV4wjpSseMOFafa32ggD5Q3LgDQHRgISniM1+DKZSTnFemvXw 3wJWkS0e/SqzyUZST9Fj96yx55xRxQMtTonyNNuCWyeObU4YNYhx0jMt3uqIpSf3Defm btWbdptUzbuYrZ4cf/Q56RzBPSzsOSNjVzPMtbcFCHyFfcYSaXorV0t0OoOPb+dQEm7g CXRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=l0364bIasEWF4u6q6PoJgdA0dWNvfPQBCr9kLEyFzmc=; b=GHc8oFIFyCbci5nwXEGapzVx5MZz4342lwdkF6yKbzesihZAto9znyefFkBgoEGt40 pi65lnlym/d5dC2RgUVkkw1va6p/LvtqzsdiRQkqRHBY0NgFN/YUaRK7CF5oL+LsO3qF cPY5/hFXGa7+4hlcMKPnRCHBs6wVWbRTPwM2AXVEHJKpFAkhlrI9djjv+zomHHEbwH24 uLeFFqgnzKmEo4JkNWVKz6Nz6piifHgvT7szSIXy6v2fj++LRorKxwYGxxuRuAvupuMt 39V2pfSPZ6AoDP4wRb+GsWSYQ2jxwS2DP/D7frI8AoaNmgivl7z6A1UCcCSRlBvg+ts3 qNIw== X-Gm-Message-State: APjAAAWkuVNslXlwzrtgekm6NuQLGROm4X0JBUdqUBtGgnbClf1FiFq9 mcgG0+hhcMr6GIpDjevVUyo= X-Received: by 2002:a17:90a:b883:: with SMTP id o3mr13734677pjr.50.1562171554721; Wed, 03 Jul 2019 09:32:34 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id a3sm3042487pff.122.2019.07.03.09.32.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 09:32:34 -0700 (PDT) From: Fuqian Huang Cc: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH v2 34/35] sound/soc/codecs: Use kmemdup rather than duplicating its implementation Date: Thu, 4 Jul 2019 00:32:24 +0800 Message-Id: <20190703163224.1029-1-huangfq.daxian@gmail.com> X-Mailer: git-send-email 2.11.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Acked-by: Richard Fitzgerald Signed-off-by: Fuqian Huang --- Changes in v2: - Fix a typo in commit message (memset -> memcpy) - Split into two patches sound/soc/codecs/wm0010.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sound/soc/codecs/wm0010.c b/sound/soc/codecs/wm0010.c index 727d6703c905..807826f30f58 100644 --- a/sound/soc/codecs/wm0010.c +++ b/sound/soc/codecs/wm0010.c @@ -515,7 +515,7 @@ static int wm0010_stage2_load(struct snd_soc_component *component) dev_dbg(component->dev, "Downloading %zu byte stage 2 loader\n", fw->size); /* Copy to local buffer first as vmalloc causes problems for dma */ - img = kzalloc(fw->size, GFP_KERNEL | GFP_DMA); + img = kmemdup(&fw->data[0], fw->size, GFP_KERNEL | GFP_DMA); if (!img) { ret = -ENOMEM; goto abort2; @@ -527,8 +527,6 @@ static int wm0010_stage2_load(struct snd_soc_component *component) goto abort1; } - memcpy(img, &fw->data[0], fw->size); - spi_message_init(&m); memset(&t, 0, sizeof(t)); t.rx_buf = out; -- 2.11.0