Skip to content

Commit ee024d4

Browse files
Jiri Slabygregkh
authored andcommitted
ALPHA: srmcons, fix racy singleton structure
The test and the assignment were racy. Make it really a singleton. This is achieved by one global variable initialized at the module init. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Matt Turner <mattst88@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5e88e6c commit ee024d4

1 file changed

Lines changed: 5 additions & 35 deletions

File tree

‎arch/alpha/kernel/srmcons.c‎

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct srmcons_private {
3333
struct tty_struct *tty;
3434
struct timer_list timer;
3535
spinlock_t lock;
36-
};
36+
} srmcons_singleton;
3737

3838
typedef union _srmcons_result {
3939
struct {
@@ -153,44 +153,11 @@ srmcons_chars_in_buffer(struct tty_struct *tty)
153153
return 0;
154154
}
155155

156-
static int
157-
srmcons_get_private_struct(struct srmcons_private **ps)
158-
{
159-
static struct srmcons_private *srmconsp = NULL;
160-
static DEFINE_SPINLOCK(srmconsp_lock);
161-
unsigned long flags;
162-
int retval = 0;
163-
164-
if (srmconsp == NULL) {
165-
srmconsp = kmalloc(sizeof(*srmconsp), GFP_KERNEL);
166-
spin_lock_irqsave(&srmconsp_lock, flags);
167-
168-
if (srmconsp == NULL)
169-
retval = -ENOMEM;
170-
else {
171-
srmconsp->tty = NULL;
172-
spin_lock_init(&srmconsp->lock);
173-
setup_timer(&srmconsp->timer, srmcons_receive_chars,
174-
(unsigned long)srmconsp);
175-
}
176-
177-
spin_unlock_irqrestore(&srmconsp_lock, flags);
178-
}
179-
180-
*ps = srmconsp;
181-
return retval;
182-
}
183-
184156
static int
185157
srmcons_open(struct tty_struct *tty, struct file *filp)
186158
{
187-
struct srmcons_private *srmconsp;
159+
struct srmcons_private *srmconsp = &srmcons_singleton;
188160
unsigned long flags;
189-
int retval;
190-
191-
retval = srmcons_get_private_struct(&srmconsp);
192-
if (retval)
193-
return retval;
194161

195162
spin_lock_irqsave(&srmconsp->lock, flags);
196163

@@ -236,6 +203,9 @@ static const struct tty_operations srmcons_ops = {
236203
static int __init
237204
srmcons_init(void)
238205
{
206+
spin_lock_init(&srmcons_singleton.lock);
207+
setup_timer(&srmcons_singleton.timer, srmcons_receive_chars,
208+
(unsigned long)&srmcons_singleton);
239209
if (srm_is_registered_console) {
240210
struct tty_driver *driver;
241211
int err;

0 commit comments

Comments
 (0)