From patchwork Thu Sep 5 20:47:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 825866 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CB2F1A76AF; Thu, 5 Sep 2024 20:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569261; cv=none; b=MV+wrSGCGr2WUW/6yQYFfZPhupQZg51Hvwv7TszViUAWQnOrI30G2Xa6Kn3/8KmUJ16xsaN7Cnp8MlrP6R9IFdCrRO75ygh1hIIvKopwp1znhPNdn/cq64NDsY/6NBYSuUkTw+5QJk+5C65/23+hMrAWJcfo94hFgmOVdOLHFoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569261; c=relaxed/simple; bh=qsJw1HcUe7Gj/mQM1O3YLvKuT9ECBKUAznlArU8F344=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PhqMWOCJy6xq85pEypcHZy1t2m2n9URX4HlsKwTUGDXJPbP1WjUsrjwBNhDMhuvflNVV9nYIuppM5NufyS6SuP5xyGnG10oukp38q94FkPe77Nl3bHTSZyl3wRTu2fgjvbuCLyOX39Rh7HnQRJVGROotIWJfogqs5wsn5CUKQro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=NoR3MkiV; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="NoR3MkiV" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4X0BJC2GHgzlgMVN; Thu, 5 Sep 2024 20:47:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1725569254; x=1728161255; bh=DQspN xAEnqiT6HWVkGfG0pG8H7Ac6GOoJnrw0mezREg=; b=NoR3MkiVPNYIIYRr3Sdyv IABUNEiuaVoLBj8rJuIsEToPFWCAOndvXZ/kLiqb4eRoUFn+H+zhYgxVZSRfXI15 c3HknjPW0k/hccUIWZqGTpwOFCegyzbai8SDjzCuu6vAkFpwlAw5nKQ4zPUqrgLT 2ugpEYshUlb86F/ibUxswhtNzSuZzwUpMgy6yrX3dIfN0wqGcmC5D7/z5ZqRQXJr rNOewFuH0WEwWr87hyKfncCBkGujTMo7+20U39d/Do1DlYRQP/i741xTuO7MoZy0 zptETRiOAMSKBk6bDpqbyTk2vnjb6R4lOs6rJG/6JHW7jkgu3jfUKKLtTLP3x7rt Q== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 75uldK_sVijw; Thu, 5 Sep 2024 20:47:34 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4X0BJ53FM1zlgMVP; Thu, 5 Sep 2024 20:47:33 +0000 (UTC) From: Bart Van Assche To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Andy Shevchenko , Amit Sunil Dhamne , Bart Van Assche , Hans de Goede , Heikki Krogerus , Badhri Jagan Sridharan , stable@vger.kernel.org Subject: [PATCH v2 3/3] usb: roles: Fix a false positive recursive locking complaint Date: Thu, 5 Sep 2024 13:47:09 -0700 Message-ID: <20240905204709.556577-4-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240905204709.556577-1-bvanassche@acm.org> References: <20240905204709.556577-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Suppress the following lockdep complaint by giving each sw->lock a unique lockdep key instead of using the same lockdep key for all sw->lock instances: INFO: trying to register non-static key. The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator. Cc: Hans de Goede Cc: Andy Shevchenko Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Cc: Badhri Jagan Sridharan Cc: stable@vger.kernel.org Fixes: fde0aa6c175a ("usb: common: Small class for USB role switches") Signed-off-by: Amit Sunil Dhamne Signed-off-by: Bart Van Assche --- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 7aca1ef7f44c..37556aa0eeee 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -22,6 +22,7 @@ static const struct class role_class = { struct usb_role_switch { struct device dev; + struct lock_class_key key; struct mutex lock; /* device lock*/ struct module *module; /* the module this device depends on */ enum usb_role role; @@ -329,6 +330,8 @@ static void usb_role_switch_release(struct device *dev) { struct usb_role_switch *sw = to_role_switch(dev); + mutex_destroy(&sw->lock); + lockdep_unregister_key(&sw->key); kfree(sw); } @@ -367,7 +370,8 @@ usb_role_switch_register(struct device *parent, if (!sw) return ERR_PTR(-ENOMEM); - mutex_init(&sw->lock); + lockdep_register_key(&sw->key); + mutex_init_with_key(&sw->lock, &sw->key); sw->allow_userspace_control = desc->allow_userspace_control; sw->usb2_port = desc->usb2_port;