]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/base/memory.c
drm/msm/mdp5: Fix mdp5_cfg_init error return
[mirror_ubuntu-bionic-kernel.git] / drivers / base / memory.c
index 1d60b58a8c19ec6ac5f0a04fc119a685100f4619..a3b8aebb95cb44f12bd4b7db44cf569dc62804bd 100644 (file)
@@ -224,7 +224,6 @@ static bool pages_correctly_reserved(unsigned long start_pfn)
 /*
  * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is
  * OK to have direct references to sparsemem variables in here.
- * Must already be protected by mem_hotplug_begin().
  */
 static int
 memory_block_action(unsigned long phys_index, unsigned long action, int online_type)
@@ -290,7 +289,6 @@ static int memory_subsys_online(struct device *dev)
        if (mem->online_type < 0)
                mem->online_type = MMOP_ONLINE_KEEP;
 
-       /* Already under protection of mem_hotplug_begin() */
        ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
 
        /* clear online_type */
@@ -337,19 +335,11 @@ store_mem_state(struct device *dev,
                goto err;
        }
 
-       /*
-        * Memory hotplug needs to hold mem_hotplug_begin() for probe to find
-        * the correct memory block to online before doing device_online(dev),
-        * which will take dev->mutex.  Take the lock early to prevent an
-        * inversion, memory_subsys_online() callbacks will be implemented by
-        * assuming it's already protected.
-        */
-       mem_hotplug_begin();
-
        switch (online_type) {
        case MMOP_ONLINE_KERNEL:
        case MMOP_ONLINE_MOVABLE:
        case MMOP_ONLINE_KEEP:
+               /* mem->online_type is protected by device_hotplug_lock */
                mem->online_type = online_type;
                ret = device_online(&mem->dev);
                break;
@@ -360,7 +350,6 @@ store_mem_state(struct device *dev,
                ret = -EINVAL; /* should never happen */
        }
 
-       mem_hotplug_done();
 err:
        unlock_device_hotplug();
 
@@ -517,15 +506,20 @@ memory_probe_store(struct device *dev, struct device_attribute *attr,
        if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1))
                return -EINVAL;
 
+       ret = lock_device_hotplug_sysfs();
+       if (ret)
+               return ret;
+
        nid = memory_add_physaddr_to_nid(phys_addr);
-       ret = add_memory(nid, phys_addr,
-                        MIN_MEMORY_BLOCK_SIZE * sections_per_block);
+       ret = __add_memory(nid, phys_addr,
+                          MIN_MEMORY_BLOCK_SIZE * sections_per_block);
 
        if (ret)
                goto out;
 
        ret = count;
 out:
+       unlock_device_hotplug();
        return ret;
 }
 
@@ -552,6 +546,9 @@ store_soft_offline_page(struct device *dev,
        pfn >>= PAGE_SHIFT;
        if (!pfn_valid(pfn))
                return -ENXIO;
+       /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */
+       if (!pfn_to_online_page(pfn))
+               return -EIO;
        ret = soft_offline_page(pfn_to_page(pfn), 0);
        return ret == 0 ? count : ret;
 }