Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp422264imu; Tue, 8 Jan 2019 23:29:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN6oTErSWnCDH+lOinOAf6llqMftWxLVNa0mjFu8W7CNo8hsPD3Olme//jsg0rpNJON8Fsnp X-Received: by 2002:a17:902:925:: with SMTP id 34mr4799774plm.14.1547018952247; Tue, 08 Jan 2019 23:29:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547018952; cv=none; d=google.com; s=arc-20160816; b=l8sfOUTPtaaKrySNAwxji1MraVm8s/RQRf2Msa44G4av0HmtLNTwOp6q/yva+8rkDm rbRMujWNColmWggzHANJgi3EoNq6rTvHK1CHIYOFJ30WOFUBoMIWvMjHei5yo7/g3wqu KpXdboEse0sXvjhz92oUiLk0OYLh128DcVPIyV/Pxy+/HMjW5AQC5ANppMWinJMXL34/ vOr3QcHo0Rzvc4ECA/QgSuhcRTZrupEvnRPbxPHNy3eYlg1DgOdjlX9tl0HEm8kpveNN r1yFIjZ3tncHZEPP1IwUStMX2xg41wOPrx+YFrXLsu7Xwph+mlBquBMrgjg7fHo0QEZu a4ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=0Yj8Db8wXhEA1gYEAoxbFmsOXCni4n6GcIt+AD7Uyps=; b=pzInyziim+sny+XpV9TQD/Am9n90jXq71hd1kaU28Iax+4J3rzz75jr/+N2DW8dOH8 GkMK+lE1noa++MiPwRpWgCmVNhLgZIN1igu6Gq/2BPz64b2rqTrXbrvxPtXnHXtEI478 BGBOlB4ZXc1eg/lVQrZTc0MOrQObYhQ4PjlRp5vz1KngMNF9j7uS2G8oJGlVaENI06QP m0hzTtndEcIpvWj88WgCOFeBm5bo4LVhNyIsqqfGG1cCCCvo5gZhvmF9dsqGdudydHfp 2ERhoYnkHJ6mwfbtxVOBSE7SwbN7JcafgeEgOOojtyeaTELObluu+y2ZJ0cWzLeodeXu vKqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=Ly+8Vl3Z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si3680761pfi.12.2019.01.08.23.28.57; Tue, 08 Jan 2019 23:29:12 -0800 (PST) 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=pass header.i=@umn.edu header.s=google header.b=Ly+8Vl3Z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729938AbfAIH0J (ORCPT + 99 others); Wed, 9 Jan 2019 02:26:09 -0500 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:60218 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729435AbfAIH0G (ORCPT ); Wed, 9 Jan 2019 02:26:06 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 3566AB1E for ; Wed, 9 Jan 2019 07:26:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OLDtu1TYZ2Sr for ; Wed, 9 Jan 2019 01:26:05 -0600 (CST) Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id 06600B07 for ; Wed, 9 Jan 2019 01:26:05 -0600 (CST) Received: by mail-io1-f71.google.com with SMTP id k4so5659133ioc.10 for ; Tue, 08 Jan 2019 23:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0Yj8Db8wXhEA1gYEAoxbFmsOXCni4n6GcIt+AD7Uyps=; b=Ly+8Vl3ZSBnaiKK2gMYiZJiB8vLlhJF4tmuSPeVc4nS8nT2rC9APQZMewKoPkUxT5q LJJDj6+7Zru+3lnbSECfgV0mNBZ9RKYX3RaOYnPAel/bpeM4zQEIkYLOdvMrku7FFZ93 cIMx6QalqJ1/cikSFk60qAOUTmxqTMN33Xl9RMe9+9/V/Y0tsxzh5nI/WtXU+KHvFyfP 2mVXHlBI5QorHQTDJxTU+PZ0AAE8O/nyvirPebkAALCO4ZKykTetrisEhKhFc/pqLiOd rmPeMjEVivx7PPYM2BicdaCsyHlkyQiCRWab9Q+9s25wYPTiSzky/uad5ggVYk77e4JE yZtA== 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:in-reply-to :references; bh=0Yj8Db8wXhEA1gYEAoxbFmsOXCni4n6GcIt+AD7Uyps=; b=Vpy7ovFqkD25dopbgXYHKC86jVBhrqOwZOVJEz8PqD2AQ6PG5K37YEE7logY9ESmF1 w1dbI2triRD2IQVHJmZw7qDfIem5UNtTDUYQFnvXjfgze7SqTXlzNf/tEV60+vTobs8Z h7zXDDaf223+oHcdaaOc8aTdB9hweIaUmHn6YZmbiHprFZn2nKUatMEP+a+fCdCR84hu VuYNxek61Ks8ni3aI8v7DsJwp1BJYQD3A08dwo88i0y2kLO42rGp1EepGgBDHNr5/VjT bH3G5N8a+KL1HF8Wg4/AWCp07fOXPZoVgwfkWEBxobLl0SDe2TNfGHAKXSxCy8DeFjuo QeNQ== X-Gm-Message-State: AJcUukc21Qj1EGkDoaA8io/aGillL3147gPdBQajcojA6bGSJrgRxcmx SHQd2TfOvVgzWhoXTaNyj5qAVWFfXuXpu0xJIAYzeZpTYzBerMeJE9En2qWy90qwPBhzuY1RLHJ 3kPOFrj+8ktyK4dppJLb994cNOLir X-Received: by 2002:a24:4016:: with SMTP id n22mr3845760ita.25.1547018764606; Tue, 08 Jan 2019 23:26:04 -0800 (PST) X-Received: by 2002:a24:4016:: with SMTP id n22mr3845754ita.25.1547018764329; Tue, 08 Jan 2019 23:26:04 -0800 (PST) Received: from bee.cs.umn.edu (cs-bee0u.cs.umn.edu. [134.84.121.28]) by smtp.gmail.com with ESMTPSA id b73sm459931itd.0.2019.01.08.23.26.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 23:26:03 -0800 (PST) From: Kangjie Lu To: kjlu@umn.edu Cc: pakki001@umn.edu, Doug Gilbert , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] scsi: avoid a double-fetch and a redundant copy Date: Wed, 9 Jan 2019 01:25:57 -0600 Message-Id: <20190109072557.9818-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org What we need is only "pack_id", so do not create a heap object or copy the whole object in. The fix efficiently copies "pack_id" only and also avoids double-fetch. Signed-off-by: Kangjie Lu --- drivers/scsi/sg.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index c6ad00703c5b..13662c41058a 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -446,16 +446,8 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) } if (old_hdr->reply_len < 0) { if (count >= SZ_SG_IO_HDR) { - sg_io_hdr_t *new_hdr; - new_hdr = kmalloc(SZ_SG_IO_HDR, GFP_KERNEL); - if (!new_hdr) { - retval = -ENOMEM; - goto free_old_hdr; - } - retval =__copy_from_user - (new_hdr, buf, SZ_SG_IO_HDR); - req_pack_id = new_hdr->pack_id; - kfree(new_hdr); + retval = get_user(req_pack_id, + &((sg_io_hdr_t *)buf)->pack_id); if (retval) { retval = -EFAULT; goto free_old_hdr; -- 2.17.1