linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: typec: Check error number after calling ida_simple_get
@ 2022-01-11  7:17 Jiasheng Jiang
  2022-01-11  8:39 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2022-01-11  7:17 UTC (permalink / raw)
  To: heikki.krogerus, gregkh; +Cc: linux-usb, linux-kernel, Jiasheng Jiang

If allocation fails, the ida_simple_get() will return error number.
So altmode_id_get() may return error number.
And then id will be used in altmode_id_remove, causing the BUG_ON().
Or it will be assigned to alt->id.
Therefore, it should be better to check it and return error if fails,
like the ida_simple_get() in typec_register_port().

Fixes: 8a37d87d72f0 ("usb: typec: Bus type for alternate modes")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/usb/typec/class.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index aeef453aa658..67b3670ede99 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -516,6 +516,9 @@ typec_register_altmode(struct device *parent,
 	struct altmode *alt;
 	int ret;
 
+	if (id < 0)
+		return ERR_PTR(id);
+
 	alt = kzalloc(sizeof(*alt), GFP_KERNEL);
 	if (!alt) {
 		altmode_id_remove(parent, id);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-11  8:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-11  7:17 [PATCH] usb: typec: Check error number after calling ida_simple_get Jiasheng Jiang
2022-01-11  8:39 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).