Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7138806ybi; Thu, 13 Jun 2019 10:12:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYm3E0rRnofXfxgB6CIk7gKu46fo5q5diBy/s/JGDN+aC12r1BQt6ZTAc86pmOKjfMYL5q X-Received: by 2002:a17:902:d695:: with SMTP id v21mr72479694ply.342.1560445963201; Thu, 13 Jun 2019 10:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560445963; cv=none; d=google.com; s=arc-20160816; b=evKcCtna9lCOvacgy4yKL1Ir6jZ2G3D+fFLHCBNJgKNy/VuZUlGWiEeYJPRuZQicUS tXoKw0GTXMImEllSQqrLvzdOFaSWJPSF9+dbf1OxaggpX/6Dk2dUTZn5/3Mjqz/MQZuW IrMcPgEJc9XK9xuQNMMkvY9GqhxnSB/lNdp5kMnuhO7xgOb+vwEQw1/eXZ9xQy6mwxob 9jjfAM639wxUPbQKFSrl/iKxPwb8uNgnorP6vdbTC8+Uo+fhlSUeIsab/TwFBb266CXq tVLVnQhomGiNc1QhSt3wZPwMJd02I54tuzHrzBFCCobR+ZEGnq0TCopH+3rehMg1i1WJ /2hQ== 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:to:from; bh=te/YloKGWFSOu8N0asszGS2BUBjmzLVy8RoYjVZY2q0=; b=1D3jNQ/xfbxZYQarV/cXaq+hoPyOgZhZ+ZX0CfAUhbUNmfICvXsNsV9KxuJGq2kabS iGv7ZkH1cwZDzpz1KQe/iAdDHdef3NTkGcTTXbHPTTzhu4bUruMiejj8GXDX6fNfn+TU YALxvsvmeZol+Sy/2Yg66YJsd0vpKmpPb0+FH6Pyc0VyCTbBvUBsLPLKL8ERrDxSh+8q elIO+dt+8D03Kx2Ajz029AN5iKFafpi4s2UP+xp3UrPWvFf1cNgI9Jtmx10LyLFNOiH8 6NMRVuaGZr00Lfq0MIElPxZwwm7eF4fXfJkoacJbieQG9h31KfK7a5nK+0OD/+rjBVnH AxaA== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m6si208191pjl.60.2019.06.13.10.12.28; Thu, 13 Jun 2019 10:12:43 -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; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393600AbfFMRMQ (ORCPT + 99 others); Thu, 13 Jun 2019 13:12:16 -0400 Received: from mga18.intel.com ([134.134.136.126]:38392 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729074AbfFLWNc (ORCPT ); Wed, 12 Jun 2019 18:13:32 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2019 15:13:31 -0700 X-ExtLoop1: 1 Received: from fei-dev-host.jf.intel.com ([10.7.198.158]) by orsmga007.jf.intel.com with ESMTP; 12 Jun 2019 15:13:31 -0700 From: fei.yang@intel.com To: felipe.balbi@linux.intel.com, john.stultz@linaro.org, mgautam@codeaurora.org, andrzej.p@samsung.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH] usb: gadget: f_fs: data_len used before properly set Date: Wed, 12 Jun 2019 15:13:26 -0700 Message-Id: <1560377606-40855-1-git-send-email-fei.yang@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fei Yang The following line of code in function ffs_epfile_io is trying to set flag io_data->use_sg in case buffer required is larger than one page. io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; However at this point of time the variable data_len has not been set to the proper buffer size yet. The consequence is that io_data->use_sg is always set regardless what buffer size really is, because the condition (data_len > PAGE_SIZE) is effectively an unsigned comparison between -EINVAL and PAGE_SIZE which would always result in TRUE. Fixes: 772a7a724f69 ("usb: gadget: f_fs: Allow scatter-gather buffers") Signed-off-by: Fei Yang Cc: stable --- drivers/usb/gadget/function/f_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 47be961..c7ed900 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -997,7 +997,6 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) * earlier */ gadget = epfile->ffs->gadget; - io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; spin_lock_irq(&epfile->ffs->eps_lock); /* In the meantime, endpoint got disabled or changed. */ @@ -1012,6 +1011,8 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) */ if (io_data->read) data_len = usb_ep_align_maybe(gadget, ep->ep, data_len); + + io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; spin_unlock_irq(&epfile->ffs->eps_lock); data = ffs_alloc_buffer(io_data, data_len); -- 2.7.4