Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1103806ybi; Wed, 3 Jul 2019 09:32:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwknniop/cbTzhwyb2p1Aevf8FzU37j23mncV8cc/XvDClt0no3zn7qVu17IH0zIOoGlUwM X-Received: by 2002:a63:553:: with SMTP id 80mr6556770pgf.280.1562171579795; Wed, 03 Jul 2019 09:32:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562171579; cv=none; d=google.com; s=arc-20160816; b=aVLyC4aUXcy1hGVNke5rVu/+g+0hUvVE1q5NJo2HuBmhuQukzgtpqST7bMYSggXB8L 4XvWsAB7T0duGeM/DrOvcAqVAgFhbixJrbsLHC5MFu2lKSNnTtHDzdwuJneR1Qo9eAUh XRDv+on139XwQvT5Vo4i6CQI4IMGoQLZ90wP1oJ2tP5LW9virP1jX6ZDvn6Cd0e0jOzS 5keVnZS+rxQ3oUqy4Y38MVuJh0yw8Z2i8VyguuLzR3Rtp1FD4fGMVWsQBIrq2zp9ukPR 1RT8ntm1B6LNNmQTG3xAeOCmUsKtsyu1385ksxpApXHCJk30vZh/tLL2gTe1Ce4aUNlO r1zw== 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=Gkn3vtw/wKbiE9yDLNxFjk7ZvpNBqpkx3Gx9EfielCI=; b=Ak8ybrI2ynfgqEJFwDnYI9nyy5uNvKUMb/1VRKgxIf9VtpKUf+SI9MN/dsGeKbP3nq cvCUPuGtZkK7BuDur7AkdZEusKwk8SH8tkHEdYHuyuaJJu5SdqiKF12clngffyhd3+iN SreNoNUsL20zYG/nM+QZLYjeKAvZ1d2GYw65XT25a92Sbe4W6wV76Q59t46S03q8P2Gd Mjv+zY67MU7AI6RbMThFH7LW3Y2YuSWXT1R4SKh8YG/56NcHIvsle7QbbQe9k8L2HFCR I9WekfGi+U0k9U1YuSfV5MvmG3cKFAJ4/H3SDIop3Ocdhk5YJj4fLzLPPZ2LUMq3ke4A 9fmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rYr3n8ck; 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 g2si2528155plp.1.2019.07.03.09.32.44; Wed, 03 Jul 2019 09:32:59 -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=rYr3n8ck; 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 S1727231AbfGCQac (ORCPT + 99 others); Wed, 3 Jul 2019 12:30:32 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40185 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbfGCQab (ORCPT ); Wed, 3 Jul 2019 12:30:31 -0400 Received: by mail-pf1-f193.google.com with SMTP id p184so1529780pfp.7; Wed, 03 Jul 2019 09:30:31 -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=Gkn3vtw/wKbiE9yDLNxFjk7ZvpNBqpkx3Gx9EfielCI=; b=rYr3n8ckCCzYVUXCL/A/uAB08qfjJ3q8sWPmBaZ7L8mjcTkkF7CEttydEnNjLmmJey JNqD+ktv97HFpLXtH/3YY+jIxwKAocicJaUO+j/iTAvM65cgBX/zXT8oEWXfC/+hw4I8 yDoiHEZ7RO/oDuwRsirPqQ+6vPlhR73LmeND8hCYLPIrAd/lzmie8OzR8HftMtOeXU88 QHCE3g0fMiVOCVTgtPPdQY8A34C95zSxiI27lZ38mWnoMjw+46KOwQ8mO1fMwLJY5f3D f8HidmLiwRlkerfali1Baq3zwa1LJbgbSz9YIUnoDPcm4hrPvQaPlccFIpZE/UKJnxs4 8Dkw== 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=Gkn3vtw/wKbiE9yDLNxFjk7ZvpNBqpkx3Gx9EfielCI=; b=eib7x0DeXn+4PR849AVwLAQVEZWPYLnhU6ncwUp+jJ/vrfKnl4bPoEhjuZ8srtnfXv uoALXuvDqjZNmHETb9gj2V2F7aNzPvrOUxRE45NXdEkvOcsqLdUW9LrA3gItGWYx5YK7 g/3NDvkMkQncqZDzmtrC+RQac42RqopgTtWmk0SVBJmQQfFcpctwfDHgC59lU7WdE+cf iVsEq9QENTUtGEAxdVDErQk+ePbX0wcVNZM7xl2Oeo1ZrNnBtNc4LwfpJ980oRcCU/Q1 9Ho68iJ/y041J2fzcOVxb40/747qED/GcmOJobvmpOfZwWo8wi+50QI9f0dh+Y4GXjEj W9uw== X-Gm-Message-State: APjAAAUuHujp/Lu7NYNBwt6d8FZVKV06dl/Y0x3jMuwzZ4kuEbDMLjP4 PQrL61zDuP8wz9BmrMQ2M10= X-Received: by 2002:a63:a35c:: with SMTP id v28mr23334581pgn.144.1562171431084; Wed, 03 Jul 2019 09:30:31 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id b19sm2959684pgh.57.2019.07.03.09.30.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 09:30:30 -0700 (PDT) From: Fuqian Huang Cc: Hannes Reinecke , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH v2 23/35] scsi: Use kmemdup rather than duplicating its implementation Date: Thu, 4 Jul 2019 00:30:22 +0800 Message-Id: <20190703163022.410-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. Signed-off-by: Fuqian Huang --- Changes in v2: - Fix a typo in commit message (memset -> memcpy) drivers/scsi/myrb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c index 539ac8ce4fcd..5e6b5e7ae93a 100644 --- a/drivers/scsi/myrb.c +++ b/drivers/scsi/myrb.c @@ -1658,14 +1658,12 @@ static int myrb_ldev_slave_alloc(struct scsi_device *sdev) if (!ldev_info) return -ENXIO; - sdev->hostdata = kzalloc(sizeof(*ldev_info), GFP_KERNEL); + sdev->hostdata = kmemdup(ldev_info, sizeof(*ldev_info), GFP_KERNEL); if (!sdev->hostdata) return -ENOMEM; dev_dbg(&sdev->sdev_gendev, "slave alloc ldev %d state %x\n", ldev_num, ldev_info->state); - memcpy(sdev->hostdata, ldev_info, - sizeof(*ldev_info)); switch (ldev_info->raid_level) { case MYRB_RAID_LEVEL0: level = RAID_LEVEL_LINEAR; -- 2.11.0