[PATCH 2/4] ipmi: bt-bmc: Track open state per device

From: Yu-Che Hsieh via B4 Relay

Date: Mon Jun 29 2026 - 02:53:36 EST


From: Yu-Che Hsieh <yc_hsieh@xxxxxxxxxxxxxx>

The driver uses a global open count to allow only one userspace client

to open the BT device at a time. This works for a single device, but

also prevents independent BT device instances from being opened

concurrently.

Move the open count into struct bt_bmc so each device instance tracks

its own open state. This preserves the single-open behavior per device

while allowing multiple BT devices to operate independently.

Signed-off-by: Yu-Che Hsieh <yc_hsieh@xxxxxxxxxxxxxx>
---
drivers/char/ipmi/bt-bmc.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/char/ipmi/bt-bmc.c b/drivers/char/ipmi/bt-bmc.c
index f3c67272502f..486ecc0b6815 100644
--- a/drivers/char/ipmi/bt-bmc.c
+++ b/drivers/char/ipmi/bt-bmc.c
@@ -64,10 +64,9 @@ struct bt_bmc {
wait_queue_head_t queue;
struct timer_list poll_timer;
struct mutex mutex;
+ atomic_t open_count;
};

-static atomic_t open_count = ATOMIC_INIT(0);
-
static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
{
return readb(bt_bmc->base + reg);
@@ -152,12 +151,12 @@ static int bt_bmc_open(struct inode *inode, struct file *file)
{
struct bt_bmc *bt_bmc = file_bt_bmc(file);

- if (atomic_inc_return(&open_count) == 1) {
+ if (atomic_inc_return(&bt_bmc->open_count) == 1) {
clr_b_busy(bt_bmc);
return 0;
}

- atomic_dec(&open_count);
+ atomic_dec(&bt_bmc->open_count);
return -EBUSY;
}

@@ -313,7 +312,7 @@ static int bt_bmc_release(struct inode *inode, struct file *file)
{
struct bt_bmc *bt_bmc = file_bt_bmc(file);

- atomic_dec(&open_count);
+ atomic_dec(&bt_bmc->open_count);
set_b_busy(bt_bmc);
return 0;
}
@@ -425,6 +424,8 @@ static int bt_bmc_probe(struct platform_device *pdev)
if (IS_ERR(bt_bmc->base))
return PTR_ERR(bt_bmc->base);

+ atomic_set(&bt_bmc->open_count, 0);
+
mutex_init(&bt_bmc->mutex);
init_waitqueue_head(&bt_bmc->queue);


--
2.34.1