Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42b426ec authored by Jing Huang's avatar Jing Huang Committed by James Bottomley
Browse files

[SCSI] bfa: protect idr using bfad_mutex



idr is a global resource, protect it with global bfad_mutex.

Signed-off-by: default avatarJing Huang <huangj@brocade.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@suse.de>
parent b3522f08
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -33,7 +33,7 @@
#include <fcb/bfa_fcb.h>
#include <fcb/bfa_fcb.h>


BFA_TRC_FILE(LDRV, BFAD);
BFA_TRC_FILE(LDRV, BFAD);
static DEFINE_MUTEX(bfad_mutex);
DEFINE_MUTEX(bfad_mutex);
LIST_HEAD(bfad_list);
LIST_HEAD(bfad_list);
static int      bfad_inst;
static int      bfad_inst;
int bfad_supported_fc4s;
int bfad_supported_fc4s;
+1 −0
Original line number Original line Diff line number Diff line
@@ -293,5 +293,6 @@ extern struct list_head bfad_list;
extern int bfa_lun_queue_depth;
extern int bfa_lun_queue_depth;
extern int bfad_supported_fc4s;
extern int bfad_supported_fc4s;
extern int bfa_linkup_delay;
extern int bfa_linkup_delay;
extern struct mutex bfad_mutex;


#endif /* __BFAD_DRV_H__ */
#endif /* __BFAD_DRV_H__ */
+9 −4
Original line number Original line Diff line number Diff line
@@ -518,7 +518,9 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
{
{
	int error = 1;
	int error = 1;


	mutex_lock(&bfad_mutex);
	if (!idr_pre_get(&bfad_im_port_index, GFP_KERNEL)) {
	if (!idr_pre_get(&bfad_im_port_index, GFP_KERNEL)) {
		mutex_unlock(&bfad_mutex);
		printk(KERN_WARNING "idr_pre_get failure\n");
		printk(KERN_WARNING "idr_pre_get failure\n");
		goto out;
		goto out;
	}
	}
@@ -526,10 +528,13 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
	error = idr_get_new(&bfad_im_port_index, im_port,
	error = idr_get_new(&bfad_im_port_index, im_port,
					 &im_port->idr_id);
					 &im_port->idr_id);
	if (error) {
	if (error) {
		mutex_unlock(&bfad_mutex);
		printk(KERN_WARNING "idr_get_new failure\n");
		printk(KERN_WARNING "idr_get_new failure\n");
		goto out;
		goto out;
	}
	}


	mutex_unlock(&bfad_mutex);

	im_port->shost = bfad_os_scsi_host_alloc(im_port, bfad);
	im_port->shost = bfad_os_scsi_host_alloc(im_port, bfad);
	if (!im_port->shost) {
	if (!im_port->shost) {
		error = 1;
		error = 1;
@@ -563,7 +568,9 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
out_fc_rel:
out_fc_rel:
	scsi_host_put(im_port->shost);
	scsi_host_put(im_port->shost);
out_free_idr:
out_free_idr:
	mutex_lock(&bfad_mutex);
	idr_remove(&bfad_im_port_index, im_port->idr_id);
	idr_remove(&bfad_im_port_index, im_port->idr_id);
	mutex_unlock(&bfad_mutex);
out:
out:
	return error;
	return error;
}
}
@@ -571,8 +578,6 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
void
void
bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
{
{
	unsigned long flags;

	bfa_trc(bfad, bfad->inst_no);
	bfa_trc(bfad, bfad->inst_no);
	bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_HOST_FREE,
	bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_HOST_FREE,
			im_port->shost->host_no);
			im_port->shost->host_no);
@@ -582,9 +587,9 @@ bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
	scsi_remove_host(im_port->shost);
	scsi_remove_host(im_port->shost);
	scsi_host_put(im_port->shost);
	scsi_host_put(im_port->shost);


	spin_lock_irqsave(&bfad->bfad_lock, flags);
	mutex_lock(&bfad_mutex);
	idr_remove(&bfad_im_port_index, im_port->idr_id);
	idr_remove(&bfad_im_port_index, im_port->idr_id);
	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
	mutex_unlock(&bfad_mutex);
}
}


static void
static void