Commit e0a5a6c3 authored by Mingkai Hu's avatar Mingkai Hu Committed by Kumar Gala

powerpc/mpic_msgr: add lock for MPIC message global variable

Also fix issue of accessing invalid msgr pointer issue. The local
msgr pointer in fucntion mpic_msgr_get will be accessed before
getting a valid address which will cause kernel crash.
Signed-off-by: default avatarMingkai Hu <Mingkai.hu@freescale.com>
Signed-off-by: default avatarKumar Gala <galak@kernel.crashing.org>
parent bdce27c7
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
static struct mpic_msgr **mpic_msgrs; static struct mpic_msgr **mpic_msgrs;
static unsigned int mpic_msgr_count; static unsigned int mpic_msgr_count;
static DEFINE_RAW_SPINLOCK(msgrs_lock);
static inline void _mpic_msgr_mer_write(struct mpic_msgr *msgr, u32 value) static inline void _mpic_msgr_mer_write(struct mpic_msgr *msgr, u32 value)
{ {
...@@ -56,12 +57,11 @@ struct mpic_msgr *mpic_msgr_get(unsigned int reg_num) ...@@ -56,12 +57,11 @@ struct mpic_msgr *mpic_msgr_get(unsigned int reg_num)
if (reg_num >= mpic_msgr_count) if (reg_num >= mpic_msgr_count)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
raw_spin_lock_irqsave(&msgr->lock, flags); raw_spin_lock_irqsave(&msgrs_lock, flags);
if (mpic_msgrs[reg_num]->in_use == MSGR_FREE) { msgr = mpic_msgrs[reg_num];
msgr = mpic_msgrs[reg_num]; if (msgr->in_use == MSGR_FREE)
msgr->in_use = MSGR_INUSE; msgr->in_use = MSGR_INUSE;
} raw_spin_unlock_irqrestore(&msgrs_lock, flags);
raw_spin_unlock_irqrestore(&msgr->lock, flags);
return msgr; return msgr;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment