->free_disk is only called after disk is added successfully, so drop ublk device reference in case of add_disk() failure.
Unified · Split
| @@ -1190,6 +1190,11 @@ static int ublk_ctrl_start_dev(struct io_uring_cmd *cmd) · 1189 unmodified lines | ||
| 1190 | 1190 | get_device(&ub->cdev_dev); |
| 1191 | 1191 | ret = add_disk(disk); |
| 1192 | 1192 | if (ret) { |
| 1193 | + /* | |
| 1194 | + * Has to drop the reference since ->free_disk won't be | |
| 1195 | + * called in case of add_disk failure. | |
| 1196 | + */ | |
| 1197 | + ublk_put_device(ub); | |
| 1193 | 1198 | put_disk(disk); |
| 1194 | 1199 | goto out_unlock; |
| 1195 | 1200 | } |