static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct mtd_concat *concat = CONCAT(mtd); int i, err = -EINVAL; for (i = 0; i < concat->num_subdev; i++) { struct mtd_info *subdev = concat->subdev[i]; uint64_t size; if (ofs >= subdev->size) { size = 0; ofs -= subdev->size; continue; } if (ofs + len > subdev->size) size = subdev->size - ofs; else size = len; err = mtd_lock(subdev, ofs, size); if (err) break; len -= size; if (len == 0) break; err = -EINVAL; ofs = 0; } return err; }
static ssize_t mtd_op_protect(struct cdev *cdev, size_t count, loff_t offset, int prot) { struct mtd_info *mtd = cdev->priv; if (!mtd->unlock || !mtd->lock) return -ENOSYS; if (prot) return mtd_lock(mtd, offset, count); else return mtd_unlock(mtd, offset, count); }
static void scb2_flash_remove(struct pci_dev *dev) { if (!scb2_mtd) return; /* disable flash writes */ mtd_lock(scb2_mtd, 0, scb2_mtd->size); mtd_device_unregister(scb2_mtd); map_destroy(scb2_mtd); iounmap(scb2_ioaddr); scb2_ioaddr = NULL; if (!region_fail) release_mem_region(SCB2_ADDR, SCB2_WINDOW); }
static void test_mtd_lock(void **state) { int eb = 0xBA; struct mtd_dev_info mtd; memset(&mtd, 0, sizeof(mtd)); mtd.bb_allowed = 1; mtd.eb_cnt = 1024; mtd.eb_size = 128; struct erase_info_user ei; memset(&ei, 0, sizeof(ei)); ei.start = eb * mtd.eb_size; ei.length = mtd.eb_size; expect_ioctl(MEMLOCK, 0, &ei); int r = mtd_lock(&mtd, 4, eb); assert_int_equal(r, 0); (void) state; }
static void __devexit scb2_flash_remove(struct pci_dev *dev) { if (!scb2_mtd) return; /* */ mtd_lock(scb2_mtd, 0, scb2_mtd->size); mtd_device_unregister(scb2_mtd); map_destroy(scb2_mtd); iounmap(scb2_ioaddr); scb2_ioaddr = NULL; if (!region_fail) release_mem_region(SCB2_ADDR, SCB2_WINDOW); pci_set_drvdata(dev, NULL); }
static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct mtd_part *part = PART(mtd); return mtd_lock(part->master, ofs + part->offset, len); }