From patchwork Wed Mar 20 12:56:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 10861547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2177D6C2 for ; Wed, 20 Mar 2019 12:56:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06ACF28B8F for ; Wed, 20 Mar 2019 12:56:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFA0E29BA0; Wed, 20 Mar 2019 12:56:50 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY 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 590D828B8F for ; Wed, 20 Mar 2019 12:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727359AbfCTM4t (ORCPT ); Wed, 20 Mar 2019 08:56:49 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:43466 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727222AbfCTM4t (ORCPT ); Wed, 20 Mar 2019 08:56:49 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 748AD27C137 From: Andrzej Pietrasiewicz To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Michal Nazarewicz , kernel@collabora.com, Marek Szyprowski , Bartlomiej Zolnierkiewicz Subject: [PATCH] usb: gadget: Don't allocate zero-length buffers Date: Wed, 20 Mar 2019 13:56:41 +0100 Message-Id: <20190320125641.10690-1-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 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 Don't actually allocate anything if userspace enqueues a zero-length buffer. Otherwise vmalloc of zero-sized area will be attempted in ffs_build_sg_list(). Signed-off-by: Andrzej Pietrasiewicz --- drivers/usb/gadget/function/f_fs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 08357c5dd026..5cecfe3e9395 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -797,6 +797,9 @@ static void *ffs_build_sg_list(struct sg_table *sgt, size_t sz) static inline void *ffs_alloc_buffer(struct ffs_io_data *io_data, size_t data_len) { + if (!data_len) + return ZERO_SIZE_PTR; + if (io_data->use_sg) return ffs_build_sg_list(&io_data->sgt, data_len); @@ -805,7 +808,7 @@ static inline void *ffs_alloc_buffer(struct ffs_io_data *io_data, static inline void ffs_free_buffer(struct ffs_io_data *io_data) { - if (!io_data->buf) + if (ZERO_OR_NULL_PTR(io_data->buf)) return; if (io_data->use_sg) {