lkml.org 
[lkml]   [2014]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] serial: samsung: Move uart_register_driver call to device probe
On Tue, Jan 21, 2014 at 09:25:31AM +0000, One Thousand Gnomes wrote:
> > static DEFINE_MUTEX(foo_mutex);
> > static unsigned foo_devices;
> >
> > static int foo_probe(struct platform_device *pdev)
> > {
> > int ret;
> >
> > mutex_lock(&foo_mutex);
> > if (foo_devices++ == 0)
> > uart_register_driver(&driver);
> >
> > ret = foo_really_probe_device(pdev);
>
> We have atomic_inc_and_test and atomic_dec_and_test so it's
> fractionally less ugly.

How do atomics help here? If we do this as:

if (atomic_inc_and_test(&foo_atomic))
uart_register_driver(&driver);

Then let's think about what can happen:

CPU0 CPU1
foo_probe
atomic_inc_and_test() == true
uart_register_driver
foo_probe
atomic_inc_and_test()
really_probe_foo()
*bang*

--
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up. Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".


\
 
 \ /
  Last update: 2014-01-21 11:21    [W:0.047 / U:0.488 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site