From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325578; b=xVcOj1fjXVcrpPTA/P2icC7XAcStmZROzMOsDDjK6/uiCs8WcP2NAHPZtfmSL6zXn7kD P+I4yWeXx+Ky3EvXSJjLe/X6cVpFuFVZWKJD4LMmoIDRSQwlshw4IeFHOvnEhR0LRe24l 2fvfMqoS80kjdgh+K40YPr17sjlrMVWRNaGcGmZ52eJ3mNsnzlPsJIjassWK23caTUnzV cndMxllgQBeCcyyF3l2abEQNvfusFNuti2cvY3ohug7lpUbj34XvosXD5wf5hJ1PLqNHV 8ZsROB71+4JP0GSct6KpMFAkLflN4vSi/x0T08UXjUHv5Yat/x9TxX62FNgXoXIjmdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325578; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:MIME-Version:X-Received:Date:In-Reply-To: X-Google-Appengine-App-Id:X-Google-Appengine-App-Id-Alias:Message-ID: Subject:From:To:Cc:Content-Type; bh=bkDX4N205UC7NWc9uPo7euJPWGtIwVtA7JJT1pYq93Y=; b=KeK0fFSTMNU9oFh6ej3P3QFiMWM7QLh3umU3azYYTpm/5CLhnfdIyhRi7BDaXA9EFSUK JXZIWFuTSn/DLM15a1mfSSUsuICEHMbuWFukjb6ufrR0viuuFzcwMuRW4IMZ3Lr/SFBTU XEUEHsCnT1Hwhwj5USyI5cjtTahexNPPM3FzVvxRvzAE/guhF/7GfJrVnlzdwt6m1Fbs3 Qij75RzikayEJjJ6kzE9VnQbeUpUu9bp1Vhhg7clVdVyElIV2kys+yczpugHVlVFTSyip UmO4n2fV6ddj1Hei8sdl4GYR8p+OvpEBKc/fiw8Yqw2SVUJ4wy3TdJtsyM/awUDn8EQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.remote-ip=209.85.161.71 Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E017606A68E for ; Thu, 3 Dec 2026 19:19:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E017606A68E Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-71aefbef495so93520eaf.2 for ; Thu, 03 Dec 2026 11:19:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796325571; x=1796930371; h=content-type:cc:to:from:subject:message-id:in-reply-to:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=bkDX4N205UC7NWc9uPo7euJPWGtIwVtA7JJT1pYq93Y=; b=SbKCiSj2fni90uKrZ5S4VuVR/HgbVGWwgSUzytTzjTMaDLfVXHMGME95HOo3NC85RO aHKvl4ZnacUscR8dnwnPWne7rEKs/h+4jGIoLsDRq/TeuydnIdFrx7J/4f3DW5lY7tqO FN8A7/fIAAIGic7gOyBd5S/CmelZifzJpgz9RuzHMrOlvBoSrtjnlWf8a4aEax+qVqX6 w4cmWybRzVEouQ3oX/Sy6i+s+I62NrVHX8OnoVgwIvN7K3y07aicBUjwjWkTHfu+lxrq 71VpArSizfRbOkedCe86+nX7Jjv6WtUj3QA86EL/HjfCVBfu0GACoJG/vGOQA5V2utDq fqgg== X-Forwarded-Encrypted: i=1; AL+hErEF4ajIBRlXj/q1BEZrb13HwZklr0N/r4B4hq1pvYBM+0lZcGrOhFinMYOhqcH14FuNC4snooNPc2On7JE=@vger.kernel.org X-Gm-Message-State: APuU4Z8NoQrtc0eoLhmkQoJfe3w0nOyJfzkjEMNAkBgvSSvDakBiCQV+ rMIyF8mOoZTvyiTYy/U+oD9WoWCYAxddYhLMzfSHmkUVqdIep1cUbHrKWIhWy/ZilNLXwB726TP ixkO0jz6C7Zt5aB4Oh3x5oBr8Tvty2yP0leFPSDu6a+XrDMII3KgqSp/aKfI= X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Received: by 2002:a05:6820:2209:b0:71b:bfbf:f910 with SMTP id 006d021491bc7-71bbfbffb4amr14437370eaf.33.1796325571540; Thu, 03 Dec 2026 11:19:31 -0800 (PST) Date: Thu, 03 Dec 2026 11:19:31 -0800 In-Reply-To: <20261203191837.443069-1-vineet789thakran@gmail.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6b11c0c3.d903dc2f.c40c6.0000.GAE@google.com> Subject: Re: [syzbot] memory leak in build_fu_desc From: syzbot To: vineet789thakran@gmail.com Cc: vineet789thakran@gmail.com, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" > #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git e5aad2bdbbee783611d32599f89cea3f12f9593d Patch testing via #syz test is temporarily disabled. See https://github.com/google/syzkaller/issues/8122 for details. > > --- > diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c > index 7539817cd407..2c892db84c65 100644 > --- a/drivers/usb/gadget/function/f_uac1.c > +++ b/drivers/usb/gadget/function/f_uac1.c > @@ -23,8 +23,8 @@ > /* UAC1 spec: 3.7.2.3 Audio Channel Cluster Format */ > #define UAC1_CHANNEL_MASK 0x0FFF > > -#define USB_OUT_FU_ID (out_feature_unit_desc->bUnitID) > -#define USB_IN_FU_ID (in_feature_unit_desc->bUnitID) > +#define USB_OUT_FU_ID(_audio) ((_audio)->params.c_fu.id) > +#define USB_IN_FU_ID(_audio) ((_audio)->params.p_fu.id) > > #define EPIN_EN(_opts) ((_opts)->p_chmask != 0) > #define EPOUT_EN(_opts) ((_opts)->c_chmask != 0) > @@ -496,11 +496,11 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) > u8 control_selector = w_value >> 8; > int value = -EOPNOTSUPP; > > - if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) > is_playback = 1; > > if (control_selector == UAC_FU_MUTE) { > @@ -547,11 +547,11 @@ in_rq_min(struct usb_function *fn, const struct usb_ctrlrequest *cr) > u8 control_selector = w_value >> 8; > int value = -EOPNOTSUPP; > > - if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) > is_playback = 1; > > if (control_selector == UAC_FU_VOLUME) { > @@ -594,11 +594,11 @@ in_rq_max(struct usb_function *fn, const struct usb_ctrlrequest *cr) > u8 control_selector = w_value >> 8; > int value = -EOPNOTSUPP; > > - if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) > is_playback = 1; > > if (control_selector == UAC_FU_VOLUME) { > @@ -641,11 +641,11 @@ in_rq_res(struct usb_function *fn, const struct usb_ctrlrequest *cr) > u8 control_selector = w_value >> 8; > int value = -EOPNOTSUPP; > > - if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) > is_playback = 1; > > if (control_selector == UAC_FU_VOLUME) { > @@ -693,11 +693,11 @@ out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req) > return; > } > > - if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) > is_playback = 1; > > if (control_selector == UAC_FU_MUTE) { > @@ -742,8 +742,8 @@ out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) > u8 entity_id = (w_index >> 8) & 0xff; > u8 control_selector = w_value >> 8; > > - if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) { > memcpy(&uac1->setup_cr, cr, sizeof(*cr)); > req->context = audio; > req->complete = out_rq_cur_complete; > @@ -1277,14 +1277,14 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > out_feature_unit_desc = build_fu_desc(audio_opts->c_chmask); > if (!out_feature_unit_desc) { > status = -ENOMEM; > - goto fail; > + goto free_ac_header; > } > } > if (FUIN_EN(audio_opts)) { > in_feature_unit_desc = build_fu_desc(audio_opts->p_chmask); > if (!in_feature_unit_desc) { > status = -ENOMEM; > - goto err_free_fu; > + goto free_fu; > } > } > > @@ -1372,7 +1372,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > /* allocate instance-specific interface IDs, and patch descriptors */ > status = usb_interface_id(c, f); > if (status < 0) > - goto err_free_fu; > + goto free_fu; > ac_interface_desc.bInterfaceNumber = status; > uac1->ac_intf = status; > uac1->ac_alt = 0; > @@ -1382,7 +1382,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > if (EPOUT_EN(audio_opts)) { > status = usb_interface_id(c, f); > if (status < 0) > - goto err_free_fu; > + goto free_fu; > as_out_interface_alt_0_desc.bInterfaceNumber = status; > as_out_interface_alt_1_desc.bInterfaceNumber = status; > ac_header_desc->baInterfaceNr[ba_iface_id++] = status; > @@ -1393,7 +1393,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > if (EPIN_EN(audio_opts)) { > status = usb_interface_id(c, f); > if (status < 0) > - goto err_free_fu; > + goto free_fu; > as_in_interface_alt_0_desc.bInterfaceNumber = status; > as_in_interface_alt_1_desc.bInterfaceNumber = status; > ac_header_desc->baInterfaceNr[ba_iface_id++] = status; > @@ -1411,7 +1411,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > if (FUOUT_EN(audio_opts) || FUIN_EN(audio_opts)) { > ep = usb_ep_autoconfig(cdev->gadget, &ac_int_ep_desc); > if (!ep) > - goto err_free_fu; > + goto free_fu; > uac1->int_ep = ep; > uac1->int_ep->desc = &ac_int_ep_desc; > > @@ -1422,7 +1422,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > if (EPOUT_EN(audio_opts)) { > ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc); > if (!ep) > - goto err_free_fu; > + goto free_fu; > ss_as_out_ep_desc.bEndpointAddress = as_out_ep_desc.bEndpointAddress; > audio->out_ep = ep; > audio->out_ep->desc = &as_out_ep_desc; > @@ -1431,7 +1431,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > if (EPIN_EN(audio_opts)) { > ep = usb_ep_autoconfig(cdev->gadget, &as_in_ep_desc); > if (!ep) > - goto err_free_fu; > + goto free_fu; > ss_as_in_ep_desc.bEndpointAddress = as_in_ep_desc.bEndpointAddress; > audio->in_ep = ep; > audio->in_ep->desc = &as_in_ep_desc; > @@ -1443,7 +1443,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > status = usb_assign_descriptors(f, f_audio_desc, f_audio_desc, f_audio_ss_desc, > f_audio_ss_desc); > if (status) > - goto err_free_fu; > + goto free_fu; > > audio->out_ep_maxpsize = le16_to_cpu(as_out_ep_desc.wMaxPacketSize); > audio->in_ep_maxpsize = le16_to_cpu(as_in_ep_desc.wMaxPacketSize); > @@ -1452,7 +1452,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > sizeof(audio->params.c_srates)); > audio->params.c_ssize = audio_opts->c_ssize; > if (FUIN_EN(audio_opts)) { > - audio->params.p_fu.id = USB_IN_FU_ID; > + audio->params.p_fu.id = in_feature_unit_desc->bUnitID; > audio->params.p_fu.mute_present = audio_opts->p_mute_present; > audio->params.p_fu.volume_present = > audio_opts->p_volume_present; > @@ -1465,7 +1465,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > sizeof(audio->params.p_srates)); > audio->params.p_ssize = audio_opts->p_ssize; > if (FUOUT_EN(audio_opts)) { > - audio->params.c_fu.id = USB_OUT_FU_ID; > + audio->params.c_fu.id = out_feature_unit_desc->bUnitID; > audio->params.c_fu.mute_present = audio_opts->c_mute_present; > audio->params.c_fu.volume_present = > audio_opts->c_volume_present; > @@ -1480,18 +1480,19 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) > > status = g_audio_setup(audio, "UAC1_PCM", "UAC1_Gadget"); > if (status) > - goto err_card_register; > + usb_free_all_descriptors(f); > > - return 0; > - > -err_card_register: > - usb_free_all_descriptors(f); > -err_free_fu: > +free_fu: > + /* > + * The feature unit and AC header descriptors are shared by all > + * instances and only needed until usb_assign_descriptors() has > + * copied them, so release them on every exit path. > + */ > kfree(out_feature_unit_desc); > out_feature_unit_desc = NULL; > kfree(in_feature_unit_desc); > in_feature_unit_desc = NULL; > -fail: > +free_ac_header: > kfree(ac_header_desc); > ac_header_desc = NULL; > return status; > @@ -1819,14 +1820,6 @@ static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f) > g_audio_cleanup(audio); > usb_free_all_descriptors(f); > > - kfree(out_feature_unit_desc); > - out_feature_unit_desc = NULL; > - kfree(in_feature_unit_desc); > - in_feature_unit_desc = NULL; > - > - kfree(ac_header_desc); > - ac_header_desc = NULL; > - > audio->gadget = NULL; > } > > diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c > index a5f3d4d6c34b..6851832ca7d0 100644 > --- a/drivers/usb/gadget/function/f_uac2.c > +++ b/drivers/usb/gadget/function/f_uac2.c > @@ -31,8 +31,8 @@ > */ > #define USB_OUT_CLK_ID (out_clk_src_desc.bClockID) > #define USB_IN_CLK_ID (in_clk_src_desc.bClockID) > -#define USB_OUT_FU_ID (out_feature_unit_desc->bUnitID) > -#define USB_IN_FU_ID (in_feature_unit_desc->bUnitID) > +#define USB_OUT_FU_ID(_agdev) ((_agdev)->params.c_fu.id) > +#define USB_IN_FU_ID(_agdev) ((_agdev)->params.p_fu.id) > > #define CONTROL_ABSENT 0 > #define CONTROL_RDONLY 1 > @@ -1095,7 +1095,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > in_feature_unit_desc = build_fu_desc(p_channels); > if (!in_feature_unit_desc) { > ret = -ENOMEM; > - goto err_free_fu; > + goto free_fu; > } > } > > @@ -1163,7 +1163,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > ret = usb_interface_id(cfg, fn); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - goto err_free_fu; > + goto free_fu; > } > iad_desc.bFirstInterface = ret; > > @@ -1175,7 +1175,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > ret = usb_interface_id(cfg, fn); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - goto err_free_fu; > + goto free_fu; > } > std_as_out_if0_desc.bInterfaceNumber = ret; > std_as_out_if1_desc.bInterfaceNumber = ret; > @@ -1205,7 +1205,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > ret = usb_interface_id(cfg, fn); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - goto err_free_fu; > + goto free_fu; > } > std_as_in_if0_desc.bInterfaceNumber = ret; > std_as_in_if1_desc.bInterfaceNumber = ret; > @@ -1219,7 +1219,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > if (!uac2->int_ep) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > ret = -ENODEV; > - goto err_free_fu; > + goto free_fu; > } > > std_ac_if_desc.bNumEndpoints = 1; > @@ -1235,42 +1235,42 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > USB_SPEED_FULL, true); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - return ret; > + goto free_fu; > } > > ret = set_ep_max_packet_size_bint(dev, uac2_opts, &fs_epout_desc, > USB_SPEED_FULL, false); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - return ret; > + goto free_fu; > } > > ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epin_desc, > USB_SPEED_HIGH, true); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - return ret; > + goto free_fu; > } > > ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epout_desc, > USB_SPEED_HIGH, false); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - return ret; > + goto free_fu; > } > > ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epin_desc, > USB_SPEED_SUPER, true); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - return ret; > + goto free_fu; > } > > ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epout_desc, > USB_SPEED_SUPER, false); > if (ret < 0) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > - return ret; > + goto free_fu; > } > > if (EPOUT_EN(uac2_opts)) { > @@ -1278,7 +1278,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > if (!agdev->out_ep) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > ret = -ENODEV; > - goto err_free_fu; > + goto free_fu; > } > if (EPOUT_FBACK_IN_EN(uac2_opts)) { > agdev->in_ep_fback = usb_ep_autoconfig(gadget, > @@ -1287,7 +1287,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > dev_err(dev, "%s:%d Error!\n", > __func__, __LINE__); > ret = -ENODEV; > - goto err_free_fu; > + goto free_fu; > } > } > } > @@ -1297,7 +1297,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > if (!agdev->in_ep) { > dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); > ret = -ENODEV; > - goto err_free_fu; > + goto free_fu; > } > } > > @@ -1331,7 +1331,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, ss_audio_desc, > ss_audio_desc); > if (ret) > - goto err_free_fu; > + goto free_fu; > > agdev->gadget = gadget; > > @@ -1340,7 +1340,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > sizeof(agdev->params.p_srates)); > agdev->params.p_ssize = uac2_opts->p_ssize; > if (FUIN_EN(uac2_opts)) { > - agdev->params.p_fu.id = USB_IN_FU_ID; > + agdev->params.p_fu.id = in_feature_unit_desc->bUnitID; > agdev->params.p_fu.mute_present = uac2_opts->p_mute_present; > agdev->params.p_fu.volume_present = uac2_opts->p_volume_present; > agdev->params.p_fu.volume_min = uac2_opts->p_volume_min; > @@ -1352,7 +1352,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > sizeof(agdev->params.c_srates)); > agdev->params.c_ssize = uac2_opts->c_ssize; > if (FUOUT_EN(uac2_opts)) { > - agdev->params.c_fu.id = USB_OUT_FU_ID; > + agdev->params.c_fu.id = out_feature_unit_desc->bUnitID; > agdev->params.c_fu.mute_present = uac2_opts->c_mute_present; > agdev->params.c_fu.volume_present = uac2_opts->c_volume_present; > agdev->params.c_fu.volume_min = uac2_opts->c_volume_min; > @@ -1366,15 +1366,17 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) > agdev->notify = afunc_notify; > > ret = g_audio_setup(agdev, "UAC2 PCM", "UAC2_Gadget"); > - if (ret) > - goto err_free_descs; > - > - return 0; > + if (ret) { > + usb_free_all_descriptors(fn); > + agdev->gadget = NULL; > + } > > -err_free_descs: > - usb_free_all_descriptors(fn); > - agdev->gadget = NULL; > -err_free_fu: > +free_fu: > + /* > + * The feature unit descriptors are shared by all instances and only > + * needed until usb_assign_descriptors() has copied them, so release > + * them on every exit path. > + */ > kfree(out_feature_unit_desc); > out_feature_unit_desc = NULL; > kfree(in_feature_unit_desc); > @@ -1586,11 +1588,11 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) > "%s:%d control_selector=%d TODO!\n", > __func__, __LINE__, control_selector); > } > - } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) > is_playback = 1; > > if (control_selector == UAC_FU_MUTE) { > @@ -1675,11 +1677,11 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr) > "%s:%d control_selector=%d TODO!\n", > __func__, __LINE__, control_selector); > } > - } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) > is_playback = 1; > > if (control_selector == UAC_FU_VOLUME) { > @@ -1765,11 +1767,11 @@ out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req) > return; > } > > - if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) { > unsigned int is_playback = 0; > > - if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) > + if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) > is_playback = 1; > > if (control_selector == UAC_FU_MUTE) { > @@ -1819,8 +1821,8 @@ out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) > req->complete = uac2_cs_control_sam_freq; > return w_length; > } > - } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) || > - (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { > + } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) || > + (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) { > memcpy(&uac2->setup_cr, cr, sizeof(*cr)); > req->context = agdev; > req->complete = out_rq_cur_complete; > @@ -2305,11 +2307,6 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) > usb_free_all_descriptors(f); > > agdev->gadget = NULL; > - > - kfree(out_feature_unit_desc); > - out_feature_unit_desc = NULL; > - kfree(in_feature_unit_desc); > - in_feature_unit_desc = NULL; > } > > static struct usb_function *afunc_alloc(struct usb_function_instance *fi)