From patchwork Tue Apr 24 21:34:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry Zhang X-Patchwork-Id: 10361107 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BB2FA6038F for ; Tue, 24 Apr 2018 21:34:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAC3D2094F for ; Tue, 24 Apr 2018 21:34:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EBE528DCF; Tue, 24 Apr 2018 21:34:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 091DC27F89 for ; Tue, 24 Apr 2018 21:34:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750868AbeDXVek (ORCPT ); Tue, 24 Apr 2018 17:34:40 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36134 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750835AbeDXVej (ORCPT ); Tue, 24 Apr 2018 17:34:39 -0400 Received: by mail-pg0-f67.google.com with SMTP id i6so11801530pgv.3 for ; Tue, 24 Apr 2018 14:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3V5TRbRjt+G2NtgzfW43KGodG4SQ+2hjFcYZ0UOries=; b=nT1FMSPZwwCRZI84z2mnD3i//Hr8l2XJEtmEwde2cs0xXr5xSv/RWrCyPC0c0sCfmX 01aeOqUSkObfz608Q+ADijGIzgeV2BS0293JxezLroY6wzfXsWQfnphE79xh/+Xda12r AzwBhUs4dwzNalKPRmYygQlQT/NY2Z+ZA6xw4vyKFcxm7Hf7X06Qweg0S0ogcPgBv7bR 7/nuRCHROJByEW8PqMnW/QMWjRVOMQH94NSVnXkV2ZmWwMH/4mXWeEqVDu0O/HWpXfSr h1xMnpTfgo8lldp4o7JsFIkXVMVt562UbyoUolLYpssVAux20K1rOd2WgBT5F3R9Jtke PrsA== 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=3V5TRbRjt+G2NtgzfW43KGodG4SQ+2hjFcYZ0UOries=; b=EpUW78PnBu+HYlxaDmSPO2YRG7os0hmKvlPh8HyW6CmiPRu6huFCr16rEAxOWSVnGZ VrJkpwwdqAE/vlXTYpx0Db2aGyG1cBL0UfZXtmgNEGWF5mXTn4lPL4xmVL/7FrMt80ja v8U1DqyXIUR4ghQ9zlGvgqE87BP8dd02sn9wnNEB4Y8TW4ofMN5DiTk5LdgKOBzwthA6 I9/yXeFOo+gbhQz0NMKtv5yE+bJQHSdmY/KTAAyXeBoC2DUCRaqviLq6CF7/4uSFCbRP 33dqd0NHeBBSfo6PCelSomM3RGmZCqTCh52rPfnjddlRmikYDG9SglmQ7WJQVf7d0p7/ 4TIQ== X-Gm-Message-State: ALQs6tBe63axyzlA+pcwIqwD9WTOjFfzvmdPB6ikVTS2s0j+FB2s+jiM dpyjBjcLsZzkk7Drqy5vXChTxw== X-Google-Smtp-Source: AIpwx48q5AcghKnmRO3tBAicZaYkKOtgZCyC6vC8p8fWml8Kl6XoV6YB5ZEHo4cJUQ+ZGfKtUMat9g== X-Received: by 10.99.127.9 with SMTP id a9mr22035511pgd.347.1524605678882; Tue, 24 Apr 2018 14:34:38 -0700 (PDT) Received: from zhangjerry.mtv.corp.google.com ([2620:0:1000:1611:ee20:2649:babf:1d14]) by smtp.gmail.com with ESMTPSA id 125sm26104325pff.158.2018.04.24.14.34.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 14:34:38 -0700 (PDT) From: Jerry Zhang To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: Michal Nazarewicz , Krzysztof Opasiak , Badhri Jagan Sridharan , Andrzej Pietrasiewicz , felixhaedicke@web.de, Jerry Zhang Subject: [PATCH 4/4] usb: gadget: f_fs: Add FUNCTIONFS_CONTROL_ONLY flag Date: Tue, 24 Apr 2018 14:34:31 -0700 Message-Id: <20180424213431.178991-1-zhangjerry@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog In-Reply-To: <20180417011045.183035-1-zhangjerry@google.com> References: <20180417011045.183035-1-zhangjerry@google.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This flag allows users to directly specify when they want a ffs instance to be used for handling control requests only via the configfs control_config/ group. When the flag is set, user must set *none* of the speed descriptor flags and provide no speeds in the descriptor. This ensures that it cannot be mixed up with a normal function. Signed-off-by: Jerry Zhang --- drivers/usb/gadget/function/f_fs.c | 22 +++++++++++----------- include/uapi/linux/usb/functionfs.h | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 4b2cb9d93176..4ef37ed70c5d 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -338,11 +338,6 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, case FFS_READ_DESCRIPTORS: case FFS_READ_STRINGS: /* Copy data */ - if (unlikely(len < 16)) { - ret = -EINVAL; - break; - } - data = ffs_prepare_buffer(buf, len); if (IS_ERR(data)) { ret = PTR_ERR(data); @@ -2383,10 +2378,19 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, FUNCTIONFS_VIRTUAL_ADDR | FUNCTIONFS_EVENTFD | FUNCTIONFS_ALL_CTRL_RECIP | - FUNCTIONFS_CONFIG0_SETUP)) { + FUNCTIONFS_CONFIG0_SETUP | + FUNCTIONFS_CONTROL_ONLY)) { ret = -ENOSYS; goto error; } + if ((bool) (flags & (FUNCTIONFS_HAS_FS_DESC | + FUNCTIONFS_HAS_HS_DESC | + FUNCTIONFS_HAS_SS_DESC)) == + (bool) (flags & FUNCTIONFS_CONTROL_ONLY)) { + pr_err("Must have at least one speed descriptor " + "or CONTROL_ONLY (but not both)\n"); + goto error; + } data += 12; len -= 12; break; @@ -2466,7 +2470,7 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, len -= ret; } - if (raw_descs == data || len) { + if (len) { ret = -EINVAL; goto error; } @@ -3020,10 +3024,6 @@ static int _ffs_func_bind(struct usb_configuration *c, ENTER(); - /* Has descriptors only for speeds gadget does not support */ - if (unlikely(!(full | high | super))) - return -ENOTSUPP; - /* Allocate a single chunk, less management later on */ vlabuf = kzalloc(vla_group_size(d), GFP_KERNEL); if (unlikely(!vlabuf)) diff --git a/include/uapi/linux/usb/functionfs.h b/include/uapi/linux/usb/functionfs.h index d77ee6b65328..25e55f485a6e 100644 --- a/include/uapi/linux/usb/functionfs.h +++ b/include/uapi/linux/usb/functionfs.h @@ -24,6 +24,7 @@ enum functionfs_flags { FUNCTIONFS_EVENTFD = 32, FUNCTIONFS_ALL_CTRL_RECIP = 64, FUNCTIONFS_CONFIG0_SETUP = 128, + FUNCTIONFS_CONTROL_ONLY = 256, }; /* Descriptor of an non-audio endpoint */