Skip to content

Commit b16b435

Browse files
peterhurleyholtmann
authored andcommitted
Bluetooth: Refactor write_room() calculation
Compute the amount of space available for a single write() within rfcomm_room(); clamp to 0 for negative values. Note this patch does not change the result of the computation. Report the amount of room returned in the debug printk. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Tested-By: Alexander Holler <holler@ahsoftware.de> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 72e5108 commit b16b435

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

  • net/bluetooth/rfcomm

‎net/bluetooth/rfcomm/tty.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,18 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
348348
}
349349

350350
/* ---- Send buffer ---- */
351-
static inline unsigned int rfcomm_room(struct rfcomm_dlc *dlc)
351+
static inline unsigned int rfcomm_room(struct rfcomm_dev *dev)
352352
{
353-
/* We can't let it be zero, because we don't get a callback
354-
when tx_credits becomes nonzero, hence we'd never wake up */
355-
return dlc->mtu * (dlc->tx_credits?:1);
353+
struct rfcomm_dlc *dlc = dev->dlc;
354+
355+
/* The limit is bogus; the number of packets which can
356+
* currently be sent by the krfcommd thread has no relevance
357+
* to the number of packets which can be queued on the dlc's
358+
* tx queue.
359+
*/
360+
int limit = dlc->mtu * (dlc->tx_credits?:1);
361+
362+
return max(0, limit - atomic_read(&dev->wmem_alloc));
356363
}
357364

358365
static void rfcomm_wfree(struct sk_buff *skb)
@@ -809,16 +816,12 @@ static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, in
809816
static int rfcomm_tty_write_room(struct tty_struct *tty)
810817
{
811818
struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
812-
int room;
819+
int room = 0;
813820

814-
BT_DBG("tty %p", tty);
815-
816-
if (!dev || !dev->dlc)
817-
return 0;
821+
if (dev && dev->dlc)
822+
room = rfcomm_room(dev);
818823

819-
room = rfcomm_room(dev->dlc) - atomic_read(&dev->wmem_alloc);
820-
if (room < 0)
821-
room = 0;
824+
BT_DBG("tty %p room %d", tty, room);
822825

823826
return room;
824827
}

0 commit comments

Comments
 (0)