Skip to content

Commit

Permalink
PR #232 from dmipx: d4xx: Locking on open dfu device
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az authored Sep 3, 2024
2 parents 53e499e + c750ae7 commit 9f03f17
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions kernel/realsense/d4xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -4967,26 +4967,31 @@ static int ds5_dfu_device_open(struct inode *inode, struct file *file)
state->client->adapter);
#endif
#endif
if (state->dfu_dev.device_open_count)
mutex_lock(&state->lock);
if (state->dfu_dev.device_open_count) {
mutex_unlock(&state->lock);
return -EBUSY;
}
state->dfu_dev.device_open_count++;
if (state->dfu_dev.dfu_state_flag != DS5_DFU_RECOVERY)
state->dfu_dev.dfu_state_flag = DS5_DFU_OPEN;
state->dfu_dev.dfu_msg = devm_kzalloc(&state->client->dev,
DFU_BLOCK_SIZE, GFP_KERNEL);
if (!state->dfu_dev.dfu_msg)
if (!state->dfu_dev.dfu_msg) {
mutex_unlock(&state->lock);
return -ENOMEM;

}
file->private_data = state;
#ifdef CONFIG_TEGRA_CAMERA_PLATFORM
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 10)
/* get i2c controller and set dfu bus clock rate */
while (parent && i2c_parent_is_i2c_adapter(parent))
parent = i2c_parent_is_i2c_adapter(state->client->adapter);

if (!parent)
if (!parent) {
mutex_unlock(&state->lock);
return 0;

}
dev_dbg(&state->client->dev, "%s(): i2c-%d bus_clk = %d, set %d\n",
__func__,
i2c_adapter_id(parent),
Expand All @@ -4997,6 +5002,7 @@ static int ds5_dfu_device_open(struct inode *inode, struct file *file)
i2c_set_adapter_bus_clk_rate(parent, DFU_I2C_BUS_CLK_RATE);
#endif
#endif
mutex_unlock(&state->lock);
return 0;
};

Expand Down Expand Up @@ -5060,6 +5066,7 @@ static int ds5_dfu_device_release(struct inode *inode, struct file *file)
#endif
#endif
int ret = 0, retry = 10;
mutex_lock(&state->lock);
state->dfu_dev.device_open_count--;
if (state->dfu_dev.dfu_state_flag != DS5_DFU_RECOVERY)
state->dfu_dev.dfu_state_flag = DS5_DFU_IDLE;
Expand All @@ -5077,8 +5084,10 @@ static int ds5_dfu_device_release(struct inode *inode, struct file *file)
/* get i2c controller and restore bus clock rate */
while (parent && i2c_parent_is_i2c_adapter(parent))
parent = i2c_parent_is_i2c_adapter(state->client->adapter);
if (!parent)
if (!parent) {
mutex_unlock(&state->lock);
return 0;
}
dev_dbg(&state->client->dev, "%s(): i2c-%d bus_clk %d, restore to %d\n",
__func__, i2c_adapter_id(parent),
i2c_get_adapter_bus_clk_rate(parent),
Expand All @@ -5096,9 +5105,11 @@ static int ds5_dfu_device_release(struct inode *inode, struct file *file)
if (ret) {
dev_warn(&state->client->dev,
"%s(): no communication with d4xx\n", __func__);
mutex_unlock(&state->lock);
return ret;
}
ret = ds5_read(state, DS5_FW_BUILD, &state->fw_build);
mutex_unlock(&state->lock);
return ret;
};

Expand Down

0 comments on commit 9f03f17

Please sign in to comment.