Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4913447imu; Tue, 25 Dec 2018 12:20:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN6U1B2qXG/fV2UL5Z+1dvzo7PQ5kYjtEFRpsQjSIGqcgI3F89BU1DQneRC6h/3JN/BL9VJL X-Received: by 2002:a63:e156:: with SMTP id h22mr16664366pgk.255.1545769204545; Tue, 25 Dec 2018 12:20:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545769204; cv=none; d=google.com; s=arc-20160816; b=o6ad0u6w8Dnu1hquj79KImF3A3mGIYoo1AUaXt7xYZkNBFLbdBReb3gAk1mZ3yZBQ9 T+A2FPMeh66iHfzDtCCWaMq8ot9b+UAhnJVq4YkxPnsxxm9IfzBzqWl6tBiwmoZMNrUy lbpWymyg6pRu1J53GKvNF+4LP4kU79HJNEo/qOgn3iH3FHkXIR3Nezh1BzcNfCcnX0H0 jFgKOcKvLPLxY6JTbPWnks0yhW2oamRZPdryaqWXSHmIAhSQZZU4ZSm9smazDptfH8/K cw1Idq3mcz6PkfVwfmcfZWdukeuDPjaQyhwyW55NLwm+R/rJej1bPjjtw1P43iA0dlKI WQBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=0YUMMuCcROi6BYXQKq+oTPJcB4cWoYymcC+8Kji7Wyk=; b=VuO2H9YbE7CK/2tm5Pgct7sll7iur1Xx5JCxwvoxbcUOa8oEq9KWJeMHKHvxVy+5p+ aGwloEe3aHkKWj6aPhYxH1FAZU0CRXr9JYqNJt7x4bEIhjqXjd09VgnT8mGmnG81VJAO WGk6kq4mQK6WPdFAThhw//wUEaHES03r20uE6M774buDlLCOkC+lngio3THcGJLyHKhW OVVosUlYrSLTZ3hxJtOCxrz+X42ZuMpAma6jb9Vzc7Gx2m2nPZZBu4BNmjTGadh0+zJN M1gujLHvuU9NGLpTxy6XL/PJ8gCJXg2SnoLAv6+sEJTIxBvQtSO+HQI5gi+VdwLC2kNj w/mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=iGLfZORH; 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 102si31611477plc.277.2018.12.25.12.19.49; Tue, 25 Dec 2018 12:20:04 -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=iGLfZORH; 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 S1725889AbeLYUQ2 (ORCPT + 99 others); Tue, 25 Dec 2018 15:16:28 -0500 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:57732 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbeLYUQ2 (ORCPT ); Tue, 25 Dec 2018 15:16:28 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 67621BAD for ; Tue, 25 Dec 2018 20:16:26 +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 4HcDaUH5H2t7 for ; Tue, 25 Dec 2018 14:16:26 -0600 (CST) Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) (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 3F332B77 for ; Tue, 25 Dec 2018 14:16:26 -0600 (CST) Received: by mail-io1-f70.google.com with SMTP id o22so17561593iob.13 for ; Tue, 25 Dec 2018 12:16:26 -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; bh=0YUMMuCcROi6BYXQKq+oTPJcB4cWoYymcC+8Kji7Wyk=; b=iGLfZORHA8qB+d7Jihz9UyCfaHkNOf+nRiiEB2p6blIxM/npuuqL3po3wClw7PMgD9 KP5gciARCQcLuATfSGukkSmCLghV2+eKtb84vwBKYm2Y56qj6QVVMBlUOWXLg7SAdblj xiz9rTT/Mz/Pyt4Mk0OUuJsF+jaG9fG1BfmU51yHRnUoKQ2YGt5ljGHtUCCna/2IVh0/ 1/1qx8HXbTIiwdTeaDqo/5d8aPb8iSomNG9WoPkIJfvY5XuA38mQVO85GHdDdDcjBJDh cjbSyHdTLBrEjr8k4uKP81I0V0cMT7y7tSAFIb2rCgCFB1AIZfPlPTKWNkrQQoLB76ts pMwA== 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=0YUMMuCcROi6BYXQKq+oTPJcB4cWoYymcC+8Kji7Wyk=; b=Xk7PhgVOXB5aKyBJPOMPJztMzvkwWEeXX00KaTasM4fgK5wm7thz1rifu6kC3iw2K8 e7nITELQXrAVBu15ua3+sBMvfsQ+F/dUR1l+q7hdrI/3VXWGARtnXx4v/+YvqYwSVOPF irBn9JQXEtobG6jmEVFt1Oal8BblksiYR88bzTV79weCNltyTUp7kcgcqTsXiWq+1QKR 19ZeTLfp9tqJHj+wGbLgnAYkvVPG5NkQEybpWA4+GdxbFIriQIPofMF5duuw0rxDYxr0 DHm0fOPCxJRWa+VEXCH6iVQlxPd19YfdHnQJQumIzfezNahs7ePJwBwqkNlhYo1S74yg kxzQ== X-Gm-Message-State: AA+aEWamerzEu5Pf4fvpO6TiUWqLVlOa4OG1yMz7/jUZ5kvfE3b5kdVp jvzEVUIpcbXPRG5YbJ12DWV7g+H5Gl5AWbdqGmCDHvTz/dvz6w9ukSk8Z1D0DttljdRJgdSa7bN bF0MAE1kwVEYG0n50YSRzbqFGc1hu X-Received: by 2002:a24:e44:: with SMTP id 65mr10043150ite.154.1545768985806; Tue, 25 Dec 2018 12:16:25 -0800 (PST) X-Received: by 2002:a24:e44:: with SMTP id 65mr10043141ite.154.1545768985548; Tue, 25 Dec 2018 12:16:25 -0800 (PST) Received: from localhost.localdomain (host-173-230-104-22.mnmigsc.mn.minneapolis.us.clients.pavlovmedia.net. [173.230.104.22]) by smtp.gmail.com with ESMTPSA id y3sm15643619iol.55.2018.12.25.12.16.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Dec 2018 12:16:24 -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] scsi: avoid a double-fetch and a redundant copy Date: Tue, 25 Dec 2018 14:15:54 -0600 Message-Id: <20181225201554.69395-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.2 (Apple Git-113) 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. 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..4dacbfffd113 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.2 (Apple Git-113)