Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4088245pxb; Mon, 8 Feb 2021 07:40:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwiJU+4dBzzlUw6iLWxddCK/sVg76SjJg29/Z0vtF/PBIXGFWrgePxxvYe8GzYTqiGChjLH X-Received: by 2002:aa7:c804:: with SMTP id a4mr16908927edt.168.1612798819471; Mon, 08 Feb 2021 07:40:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612798819; cv=none; d=google.com; s=arc-20160816; b=INNI4aki8aOR7uhl73cBFFawuR/uH+H4lcJr3CfO8hc33hw2Q8kJJPFicJ3agl7rFz qR4HSKw+jPmGMRSeG2Q+8zWTLqn5zbLvR1vqZFz+sBUCGsKE4pS6gltGpZmo7teUb3Ym u0dToAo06J1So73MoDMr2aRVSke9MT1xIX31VkI8uUnJYiyNjK3bhFRSrjZpEiD6N7Q/ 7htxw0h2ahoGHFZ9mGC2j6TTUmD7OBni9zmJo/tjRzTYrjPJ4pf6N3hupW0ZcxQwj9qS 6awbGLqzoutT6na8Th1ftPadcOZvhSDSzzGfqV7lK8gazFuxhpofyLSsz1OMZoSv/jfW OIEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QStCds48YNkzjLuctV2jnh0Lv0rdVWEXG6DQRkKebj0=; b=Sq8R54U0WaYseMXzYdjeG1e+CYweZS1CLJJ3ArdD0jK0gjehua9IFWyde+lmVtma0P p9Sn3XxR1vBeR9PKQrq7VrNp/792eMVbZf9fQCOJfrDcGrMJtHdvtaRx0U9FW0esHGTj /YsfJhRLB+ogbvauN/2TPiBrg4EksRsLafx/1x06Pxw4Mpi0rOnkD4AJplp1mRbE3s82 reuZ1bkksb17/zQsbEaZqXL6ZeqzF0P5zxrEVDYrYuYnWRIWf0hXXa/Amt63FiPp5+ZO qrrBOTewp0YekoSq54WDTFiy4ZnKF0NprxzGCCKhZ1FMh2HY7NTt82/al1OZe5RucQ81 JK/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AMrnFJWw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si11668194edj.289.2021.02.08.07.39.55; Mon, 08 Feb 2021 07:40:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AMrnFJWw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234072AbhBHPiE (ORCPT + 99 others); Mon, 8 Feb 2021 10:38:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:52062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232174AbhBHPE5 (ORCPT ); Mon, 8 Feb 2021 10:04:57 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AE3AE64E88; Mon, 8 Feb 2021 15:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612796626; bh=qxbqL2wn2WiMvVxuWXwglespm/qgMOjOSaH1vLuW1G8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMrnFJWw8GedMgwtUgIyaf1HnqgdLQ1w/AxQssouSO74biA1wA2vyc0aEgWQMub9A 7Rsvz8Zve8HN0zPfawkhB61psDxhJGMSNJ0wAA7cJhwND6+Pfr8sLhPN0lns+0yw7x czwDuZHY9ZCsh1YLJuvgcV1kJHr2MyrSSY1yuwqw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Felipe Balbi , Thinh Nguyen , Sudip Mukherjee Subject: [PATCH 4.4 12/38] usb: udc: core: Use lock when write to soft_connect Date: Mon, 8 Feb 2021 16:00:34 +0100 Message-Id: <20210208145805.783244825@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145805.279815326@linuxfoundation.org> References: <20210208145805.279815326@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thinh Nguyen commit c28095bc99073ddda65e4f31f6ae0d908d4d5cd8 upstream Use lock to guard against concurrent access for soft-connect/disconnect operations when writing to soft_connect sysfs. Fixes: 2ccea03a8f7e ("usb: gadget: introduce UDC Class") Cc: stable@vger.kernel.org Acked-by: Felipe Balbi Signed-off-by: Thinh Nguyen Link: https://lore.kernel.org/r/338ea01fbd69b1985ef58f0f59af02c805ddf189.1610611437.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman [sudip: manual backporting to old file] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/udc/udc-core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -612,10 +612,13 @@ static ssize_t usb_udc_softconn_store(st struct device_attribute *attr, const char *buf, size_t n) { struct usb_udc *udc = container_of(dev, struct usb_udc, dev); + ssize_t ret; + mutex_lock(&udc_lock); if (!udc->driver) { dev_err(dev, "soft-connect without a gadget driver\n"); - return -EOPNOTSUPP; + ret = -EOPNOTSUPP; + goto out; } if (sysfs_streq(buf, "connect")) { @@ -627,10 +630,14 @@ static ssize_t usb_udc_softconn_store(st usb_gadget_udc_stop(udc); } else { dev_err(dev, "unsupported command '%s'\n", buf); - return -EINVAL; + ret = -EINVAL; + goto out; } - return n; + ret = n; +out: + mutex_unlock(&udc_lock); + return ret; } static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);