From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com ([192.55.52.88]:13398 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751322AbcCIHJQ (ORCPT ); Wed, 9 Mar 2016 02:09:16 -0500 From: Felipe Balbi To: "Felipe F. Tonello" , linux-usb@vger.kernel.org Cc: "# v4 . 4+" Subject: Re: [PATCH] usb: gadget: f_midi: added spinlock on transmit function In-Reply-To: <1457468507-25622-1-git-send-email-eu@felipetonello.com> References: <1457468507-25622-1-git-send-email-eu@felipetonello.com> Date: Wed, 09 Mar 2016 09:08:25 +0200 Message-ID: <877fhcgmc6.fsf@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Sender: stable-owner@vger.kernel.org List-ID: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, "Felipe F. Tonello" writes: > [ text/plain ] > Since f_midi_transmit is called by both ALSA and USB sub-systems, it can > potentially cause a race condition between both calls because f_midi_tran= smit > is not reentrant nor thread-safe. This is due to an implementation detail= that > the transmit function looks for the next available usb request from the f= ifo > and only enqueues it if there is data to send, otherwise just re-uses it.= So, > if both ALSA and USB frameworks calls this function at the same time, > kfifo_seek() will return the same usb_request, which will cause a race > condition. > > To solve this problem a syncronization mechanism is necessary. In this ca= se it > is used a spinlock since f_midi_transmit is also called by usb_request->c= omplete > callback in interrupt context. > > Cc: # v4.4+ > Fixes: e1e3d7ec5da3 ("usb: gadget: f_midi: pre-allocate IN requests") > Signed-off-by: Felipe F. Tonello > Tested-by: Felipe F. Tonello adding one's own Tested-by is a bit redundant. I'll remove it while applying ;-) =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJW38vpAAoJEIaOsuA1yqREW8EQALArVWkLMZYnY7rYRSQ00wJ6 ql+Q/bGe0WFZOD54qjUM3QnTFdajuYYkDuhyWDfZiTevDZb3rQUZ2T00NPIKL2yW XaL5G00Ff3yxgejfhBnJ1gA7q5ngXTLuWkkepMYHmMCY9P0ughqW9+Ic3a5ZDVHo txJupoO3xAHbC56xARbQWQOihN05tud94R5FuoygeES34BT0HGrGRFs7hN5D7dWT JLalrWIP3Q5gTeIHTCzp5dnrLNrUr0tG9/gvt8JruLcAnpMMMVfyFqg5FVFxaWpi dEvSiCpWwcKsd3QWqTnuhDK7LV7/lg3lXCXZSQQrdp/MoGb+5AYiWEGxtOvGdoLh VS1blvsUvrBtM6gvx+fNnBDiII2Ob3q7wmOFNg3A+s11gqHmNuwu1kOEjSTfIhGC aCePjm+Xhu2dZXebsjXjizENAgqvJJwSz2AmGjaFu2aOVIPpjIX2IAr25IR1+v5E kcqEUh38bcNITyYcNNPJ55/dvXubQoDTf9T2aUMFbAAA/7jIjMM+7iQMWUwCNUcL Wp5MUWUloPS8ba1o38XszUht9RF8Z9LCPVw2xUe1GZAq4KT8YSxCSJseOzl2IFlT F+k8li8AGr18Lphb69x8mVjD+elxGGvqPRP+6bQjMBxceTQ3z38sbCjv/ZRHJEPJ IRi00bYRJY8VJShwGJxb =6S3c -----END PGP SIGNATURE----- --=-=-=--