Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08b835b7 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "usb: f_serial: Check port_num before allocating serial instance"

parents d21ab502 dfa0b432
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -1111,17 +1111,22 @@ static struct usb_function *gser_alloc(struct usb_function_instance *fi)
	struct f_gser	*gser;
	struct f_serial_opts *opts;

	opts = container_of(fi, struct f_serial_opts, func_inst);
	if (nr_ports) {
		opts->port_num = gser_next_free_port++;
		if (opts->port_num >= GSERIAL_NO_PORTS) {
			pr_err("%s: No serial allowed for port %d\n",
					__func__, opts->port_num);
			return ERR_PTR(-EINVAL);
		}
	}

	/* allocate and initialize one new instance */
	gser = kzalloc(sizeof(*gser), GFP_KERNEL);
	if (!gser)
		return ERR_PTR(-ENOMEM);

	opts = container_of(fi, struct f_serial_opts, func_inst);

	spin_lock_init(&gser->lock);
	if (nr_ports)
		opts->port_num = gser_next_free_port++;

	gser->port_num = opts->port_num;

	gser->port.func.name = "gser";