OSDN Git Service

Merge tag 'powerpc-5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[tomoyo/tomoyo-test1.git] / arch / powerpc / platforms / pseries / dtl.c
index fb05804..2b87480 100644 (file)
@@ -1,23 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Virtual Processor Dispatch Trace Log
  *
  * (C) Copyright IBM Corporation 2009
  *
  * Author: Jeremy Kerr <jk@ozlabs.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/slab.h>
@@ -193,11 +180,16 @@ static int dtl_enable(struct dtl *dtl)
        if (dtl->buf)
                return -EBUSY;
 
+       /* ensure there are no other conflicting dtl users */
+       if (!read_trylock(&dtl_access_lock))
+               return -EBUSY;
+
        n_entries = dtl_buf_entries;
        buf = kmem_cache_alloc_node(dtl_cache, GFP_KERNEL, cpu_to_node(dtl->cpu));
        if (!buf) {
                printk(KERN_WARNING "%s: buffer alloc failed for cpu %d\n",
                                __func__, dtl->cpu);
+               read_unlock(&dtl_access_lock);
                return -ENOMEM;
        }
 
@@ -214,8 +206,11 @@ static int dtl_enable(struct dtl *dtl)
        }
        spin_unlock(&dtl->lock);
 
-       if (rc)
+       if (rc) {
+               read_unlock(&dtl_access_lock);
                kmem_cache_free(dtl_cache, buf);
+       }
+
        return rc;
 }
 
@@ -227,6 +222,7 @@ static void dtl_disable(struct dtl *dtl)
        dtl->buf = NULL;
        dtl->buf_entries = 0;
        spin_unlock(&dtl->lock);
+       read_unlock(&dtl_access_lock);
 }
 
 /* file interface */