+static int scpi_alloc_mbox_chan(void)
+{
+ int index;
+
+ mutex_lock(&scpi_mtx);
+
+ index = find_first_zero_bit(bm_mbox_chans, max_chan_num);
+ if (index >= max_chan_num) {
+ pr_err("alloc mailbox channel failed\n");
+ mutex_unlock(&scpi_mtx);
+ return -EBUSY;
+ }
+
+ set_bit(index, bm_mbox_chans);
+
+ mutex_unlock(&scpi_mtx);
+ return index;
+}
+
+static void scpi_free_mbox_chan(int chan)
+{
+ int index = chan;
+
+ mutex_lock(&scpi_mtx);
+
+ if (index < max_chan_num && index >= 0)
+ clear_bit(index, bm_mbox_chans);
+
+ mutex_unlock(&scpi_mtx);
+}
+