Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp891499ybi; Wed, 3 Jul 2019 06:15:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRTMiDmN2onwMxcYME+VqcuUA3/OPZgzhzbbydKQUtuUo5h7530PjQ2FjaccBdLVv24gBQ X-Received: by 2002:a17:902:ab90:: with SMTP id f16mr41597297plr.262.1562159750236; Wed, 03 Jul 2019 06:15:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562159750; cv=none; d=google.com; s=arc-20160816; b=nJMrlhESafZysN2xATaf3aw+nNRsYASg30J//YUNydgnk4wJ80/SnBnAqSJYSrjFC2 8C/xBj2ePKXade7PpZvyC6Zgum1UHxedMROUflNVd5gafyQz1yXDiNToKDz5ZpW1vT+g 7gZ3q9ftmF0Y6Nm0miCzwVf8wyNB63tflwWBWzW/UkkkolWlEXQ21hc5cJcG6Py7dEPU oUoWQR5RSHqqqYdNHQbPjpLmO/crZ//WHCzN5RWpWlHXUqEVycFcoIseVC5FT21t8ZzL sbvWJqjpXQAIUMssZwz9UMJdyXKCmd70dN6Pru10Bferk3gkf9VEVkLcZVkBvgtKOhRq VZRQ== 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=/SnzKzwbJwdsQHXwXFz/daj/8JZPIhirrV+rjMpDDQs=; b=zC1vi83zjM53iY3sZAouH/ODmNxAFsVwUuDHQSzU5C27/v10/tSXhD9sTJOUJu7t3K 2Iyl579HwWrTkPjRQ+YA0zKmrL3KL5goaVUuIRn9b62WbB/782fe5dp9Ql05uwBTNE8/ KCycJdYIfNWrRvDGpZRPS0AtwD2ypgz7K4zVv8Y0ZdgT4hh+8Ni8RBJw6rg+KCPJI+18 YP79796g8d7mE3r6zer+pQYQfNWsbWunOK0RDkwDfMdpSs8zcrjhdw1WiXqSK7REChxA pNCBJWs+e83tJTlR01oeaoxYI5v1REEC6K6p+Obf8YBVFiVcDmpwMQ0TQqnpcvUr0suT l4jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dr0lsFRi; 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 v8si2432452pfm.83.2019.07.03.06.15.34; Wed, 03 Jul 2019 06:15:50 -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=dr0lsFRi; 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 S1726973AbfGCNNg (ORCPT + 99 others); Wed, 3 Jul 2019 09:13:36 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46884 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbfGCNNg (ORCPT ); Wed, 3 Jul 2019 09:13:36 -0400 Received: by mail-pg1-f194.google.com with SMTP id i8so1219609pgm.13 for ; Wed, 03 Jul 2019 06:13: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=/SnzKzwbJwdsQHXwXFz/daj/8JZPIhirrV+rjMpDDQs=; b=dr0lsFRiXjQ5piksHRyi/X873mKA7ZcleDGYjHaXJ5f6LYS/VE0e/SYvGVFJWfoKkj 0cIiNUXi+RTrlmuHHb0sHzMy7BgSWHdi7jb4wBHHl8UZ1HqJK/ft+gWm2y3SQNXfk+XU QbUh0VxZr8zCCGesslE6GDDmJaE54z/Phatgo8UNnCbnhSTSgINB4WBtiG4VNVbws4wp 9efLTJd/Fg82mtSy6ys1sDKZ3wzwr9O7A9JUj+nYaABvtOXSQpRzlMxlNwi3iaaP7qbG xgLdBcsi5QTE4TgK7Ikoudh1E04otuVlSb2U/SgRB07q5j6vqwTgTMLD5BvhHZQWDB3R W7lA== 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=/SnzKzwbJwdsQHXwXFz/daj/8JZPIhirrV+rjMpDDQs=; b=NlT+F2F09aTO+uiw0+Y3cXnelGImVFLsE+kn0ASdILcGTi2CgvpN0VBemnZiEukVhz gP0OptAJqaN1Kk5TQJhve/Yau7FaMWrF4sag8T0J5SwY3mACtquksTE6R+Im/iHC2fjx Qv2NtPgDZaQzDtJ2919uVwollQXPHBarunsAA9XiY36b9icb/HhN19zAYN/HpCNj4lh6 aBXcttDNulxMQ02MIffWI3h9CTiUcu1ZwX+KAxnmbnq9/efn0SeJT77sQoWQdsL/UXDK L3/QxrkKV0cy/tSYVitRsrFg1kYOkkINqoxYmIg03BhSWrSC4yW8hhIjG0cOXHep1J76 GP5Q== X-Gm-Message-State: APjAAAWfmgDeXBqQI6BSKhadqKm/Fx6dX2oyc/Skhd8alJyDjgIXj3dk I3M1nA6HCOtuIQO88+Zfxj0= X-Received: by 2002:a17:90a:b115:: with SMTP id z21mr12775207pjq.64.1562159615496; Wed, 03 Jul 2019 06:13:35 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id n89sm10811597pjc.0.2019.07.03.06.13.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 06:13:35 -0700 (PDT) From: Fuqian Huang Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH 02/30] powerpc: Use kmemdup rather than duplicating its implementation Date: Wed, 3 Jul 2019 21:13:27 +0800 Message-Id: <20190703131327.24762-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 + memset, 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 + memset. Add an allocation failure check. Signed-off-by: Fuqian Huang --- arch/powerpc/platforms/pseries/dlpar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c index 437a74173db2..20fe7b79e09e 100644 --- a/arch/powerpc/platforms/pseries/dlpar.c +++ b/arch/powerpc/platforms/pseries/dlpar.c @@ -383,9 +383,10 @@ void queue_hotplug_event(struct pseries_hp_errorlog *hp_errlog) struct pseries_hp_work *work; struct pseries_hp_errorlog *hp_errlog_copy; - hp_errlog_copy = kmalloc(sizeof(struct pseries_hp_errorlog), + hp_errlog_copy = kmemdup(hp_errlog, sizeof(struct pseries_hp_errorlog), GFP_KERNEL); - memcpy(hp_errlog_copy, hp_errlog, sizeof(struct pseries_hp_errorlog)); + if (!hp_errlog_copy) + return; work = kmalloc(sizeof(struct pseries_hp_work), GFP_KERNEL); if (work) { -- 2.11.0