Bluetooth: Fix giving back pkts semaphore when disconnecting
Bluetooth: Fix giving back pkts semaphore when disconnecting

The TX fiber might be blocked waiting for the num_pkts semaphore when
a disconnection occurs. If we only give back the semaphore once
exiting the while-loop we may end up in a deadlock. Giving back the
semaphore in the connection disconnect handler solves this.

An additional fix this patch does is to ensure that we don't perform
integer underflow because of the last iteration.

Change-Id: Ia67dc506885d0c2bad25c598ea349f1fd251218b
Signed-off-by: Johan Hedberg <628991c7b0a19c384f9b99c21ec330ce952bb838@intel.com>

nashif/zephyr,mbolivar/zephyr,runchip/zephyr-cc3220,fbsder/zephyr,Vudentz/zephyr,punitvara/zephyr,erwango/zephyr,aceofall/zephyr-iotos,ldts/zephyr,punitvara/zephyr,rsalveti/zephyr,runchip/zephyr-cc3220,galak/zephyr,finikorg/zephyr,zephyriot/zephyr,Vudentz/zephyr,GiulianoFranchetto/zephyr,tidyjiang8/zephyr-doc,holtmann/zephyr,rsalveti/zephyr,fractalclone/zephyr-riscv,nashif/zephyr,kraj/zephyr,erwango/zephyr,sharronliu/zephyr,Vudentz/zephyr,ldts/zephyr,runchip/zephyr-cc3200,runchip/zephyr-cc3200,mbolivar/zephyr,zephyrproject-rtos/zephyr,aceofall/zephyr-iotos,Vudentz/zephyr,nashif/zephyr,bboozzoo/zephyr,aceofall/zephyr-iotos,ldts/zephyr,GiulianoFranchetto/zephyr,ldts/zephyr,erwango/zephyr,erwango/zephyr,runchip/zephyr-cc3200,kraj/zephyr,galak/zephyr,aceofall/zephyr-iotos,bigdinotech/zephyr,explora26/zephyr,holtmann/zephyr,sharronliu/zephyr,tidyjiang8/zephyr-doc,mbolivar/zephyr,zephyriot/zephyr,erwango/zephyr,punitvara/zephyr,bboozzoo/zephyr,Vudentz/zephyr,zephyriot/zephyr,runchip/zephyr-cc3220,pklazy/zephyr,mbolivar/zephyr,nashif/zephyr,pklazy/zephyr,explora26/zephyr,fractalclone/zephyr-riscv,runchip/zephyr-cc3220,explora26/zephyr,runchip/zephyr-cc3200,rsalveti/zephyr,kraj/zephyr,GiulianoFranchetto/zephyr,bigdinotech/zephyr,pklazy/zephyr,holtmann/zephyr,finikorg/zephyr,finikorg/zephyr,galak/zephyr,zephyriot/zephyr,fbsder/zephyr,fbsder/zephyr,punitvara/zephyr,runchip/zephyr-cc3220,bboozzoo/zephyr,galak/zephyr,kraj/zephyr,bigdinotech/zephyr,aceofall/zephyr-iotos,zephyrproject-rtos/zephyr,tidyjiang8/zephyr-doc,punitvara/zephyr,zephyrproject-rtos/zephyr,fractalclone/zephyr-riscv,fractalclone/zephyr-riscv,kraj/zephyr,galak/zephyr,zephyriot/zephyr,mbolivar/zephyr,bigdinotech/zephyr,finikorg/zephyr,zephyrproject-rtos/zephyr,pklazy/zephyr,holtmann/zephyr,finikorg/zephyr,sharronliu/zephyr,pklazy/zephyr,GiulianoFranchetto/zephyr,sharronliu/zephyr,holtmann/zephyr,tidyjiang8/zephyr-doc,bigdinotech/zephyr,GiulianoFranchetto/zephyr,nashif/zephyr,bboozzoo/zephyr,fractalclone/zephyr-riscv,fbsder/zephyr,explora26/zephyr,explora26/zephyr,tidyjiang8/zephyr-doc,fbsder/zephyr,runchip/zephyr-cc3200,Vudentz/zephyr,bboozzoo/zephyr,ldts/zephyr,sharronliu/zephyr,zephyrproject-rtos/zephyr,rsalveti/zephyr,rsalveti/zephyr