int cmd_checkfs(struct super_block *sb, struct context *c) { struct bitmap *i_freemap, *b_freemap; int ret; if (c->nargs != 1) { return -EINVAL; } ret = bitmap_create(BLOCK_SIZE * INODE_FREEMAP_SIZE * BITS_PER_WORD, &i_freemap); if (ret < 0) return ret; ret = bitmap_create(BLOCK_SIZE * BLOCK_FREEMAP_SIZE * BITS_PER_WORD, &b_freemap); if (ret < 0) return ret; testfs_checkfs(sb, i_freemap, b_freemap, 0); if (!bitmap_equal(sb->inode_freemap, i_freemap)) { printf("inode freemap is not consistent\n"); } if (!bitmap_equal(sb->block_freemap, b_freemap)) { printf("block freemap is not consistent\n"); } printf("nr of allocated inodes = %d\n", bitmap_nr_allocated(sb->inode_freemap)); printf("nr of allocated blocks = %d\n", bitmap_nr_allocated(sb->block_freemap)); return 0; }
static int __init check_acpi_ids(struct acpi_processor *pr_backup) { if (!pr_backup) return -ENODEV; acpi_id_present = kcalloc(BITS_TO_LONGS(nr_acpi_bits), sizeof(unsigned long), GFP_KERNEL); if (!acpi_id_present) return -ENOMEM; acpi_id_cst_present = kcalloc(BITS_TO_LONGS(nr_acpi_bits), sizeof(unsigned long), GFP_KERNEL); if (!acpi_id_cst_present) { kfree(acpi_id_present); return -ENOMEM; } acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, read_acpi_id, NULL, NULL, NULL); acpi_get_devices("ACPI0007", read_acpi_id, NULL, NULL); if (!bitmap_equal(acpi_id_present, acpi_ids_done, nr_acpi_bits)) { unsigned int i; for_each_set_bit(i, acpi_id_present, nr_acpi_bits) { pr_backup->acpi_id = i; pr_backup->flags.power = test_bit(i, acpi_id_cst_present); (void)upload_pm_data(pr_backup); }
void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque, void (*fn)(const char *name, void *opaque)) { S390FeatBitmap bitmap, tmp; S390FeatGroup group; S390Feat feat; bitmap_copy(bitmap, features, S390_FEAT_MAX); /* process whole groups first */ for (group = 0; group < S390_FEAT_GROUP_MAX; group++) { const S390FeatGroupDef *def = s390_feat_group_def(group); bitmap_and(tmp, bitmap, def->feat, S390_FEAT_MAX); if (bitmap_equal(tmp, def->feat, S390_FEAT_MAX)) { bitmap_andnot(bitmap, bitmap, def->feat, S390_FEAT_MAX); fn(def->name, opaque); } } /* report leftovers as separate features */ feat = find_first_bit(bitmap, S390_FEAT_MAX); while (feat < S390_FEAT_MAX) { fn(s390_feat_def(feat)->name, opaque); feat = find_next_bit(bitmap, S390_FEAT_MAX, feat + 1); }; }
static int __init check_acpi_ids(struct acpi_processor *pr_backup) { if (!pr_backup) return -ENODEV; /* All online CPUs have been processed at this stage. Now verify * whether in fact "online CPUs" == physical CPUs. */ acpi_id_present = kcalloc(BITS_TO_LONGS(nr_acpi_bits), sizeof(unsigned long), GFP_KERNEL); if (!acpi_id_present) return -ENOMEM; acpi_id_cst_present = kcalloc(BITS_TO_LONGS(nr_acpi_bits), sizeof(unsigned long), GFP_KERNEL); if (!acpi_id_cst_present) { kfree(acpi_id_present); return -ENOMEM; } acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, read_acpi_id, NULL, NULL, NULL); acpi_get_devices("ACPI0007", read_acpi_id, NULL, NULL); if (!bitmap_equal(acpi_id_present, acpi_ids_done, nr_acpi_bits)) { unsigned int i; for_each_set_bit(i, acpi_id_present, nr_acpi_bits) { pr_backup->acpi_id = i; /* Mask out C-states if there are no _CST or PBLK */ pr_backup->flags.power = test_bit(i, acpi_id_cst_present); (void)upload_pm_data(pr_backup); }
static int __dma_device_satisfies_mask(struct dma_device *device, dma_cap_mask_t *want) { dma_cap_mask_t has; bitmap_and(has.bits, want->bits, device->cap_mask.bits, DMA_TX_TYPE_END); return bitmap_equal(want->bits, has.bits, DMA_TX_TYPE_END); }
static bool __init __check_eq_bitmap(const char *srcfile, unsigned int line, const unsigned long *exp_bmap, const unsigned long *bmap, unsigned int nbits) { if (!bitmap_equal(exp_bmap, bmap, nbits)) { pr_warn("[%s:%u] bitmaps contents differ: expected \"%*pbl\", got \"%*pbl\"\n", srcfile, line, nbits, exp_bmap, nbits, bmap); return false; } return true; }
/* Provides a bitmap of VLANs which have learning disabled, that is, VLANs on * which all packets are flooded. It takes ownership of the bitmap. Returns * true if the set has changed from the previous value. */ bool mac_learning_set_flood_vlans(struct mac_learning *ml, unsigned long *bitmap) { bool ret = (bitmap == NULL ? ml->flood_vlans != NULL : (ml->flood_vlans == NULL || !bitmap_equal(bitmap, ml->flood_vlans, 4096))); bitmap_free(ml->flood_vlans); ml->flood_vlans = bitmap; return ret; }
static void __init test_of_node(void) { u32 prop_data[] = { 10, 10, 25, 3, 40, 1, 100, 100, 200, 20 }; const char *expected_str = "0-9,20-24,28-39,41-99,220-255"; char *prop_name = "msi-available-ranges"; char *node_name = "/fakenode"; struct device_node of_node; struct property prop; struct msi_bitmap bmp; #define SIZE_EXPECTED 256 DECLARE_BITMAP(expected, SIZE_EXPECTED); /* There should really be a struct device_node allocator */ memset(&of_node, 0, sizeof(of_node)); of_node_init(&of_node); of_node.full_name = node_name; WARN_ON(msi_bitmap_alloc(&bmp, SIZE_EXPECTED, &of_node)); /* No msi-available-ranges, so expect > 0 */ WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0); /* Should all still be free */ WARN_ON(bitmap_find_free_region(bmp.bitmap, SIZE_EXPECTED, get_count_order(SIZE_EXPECTED))); bitmap_release_region(bmp.bitmap, 0, get_count_order(SIZE_EXPECTED)); /* Now create a fake msi-available-ranges property */ /* There should really .. oh whatever */ memset(&prop, 0, sizeof(prop)); prop.name = prop_name; prop.value = &prop_data; prop.length = sizeof(prop_data); of_node.properties = ∝ /* msi-available-ranges, so expect == 0 */ WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp)); /* Check we got the expected result */ WARN_ON(bitmap_parselist(expected_str, expected, SIZE_EXPECTED)); WARN_ON(!bitmap_equal(expected, bmp.bitmap, SIZE_EXPECTED)); msi_bitmap_free(&bmp); kfree(bmp.bitmap); }
static void get_feature_group(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { S390FeatGroup group = (S390FeatGroup) opaque; const S390FeatGroupDef *def = s390_feat_group_def(group); S390CPU *cpu = S390_CPU(obj); S390FeatBitmap tmp; bool value; if (!cpu->model) { error_setg(errp, "Details about the host CPU model are not available, " "features cannot be queried."); return; } /* a group is enabled if all features are enabled */ bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX); value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX); visit_type_bool(v, name, &value, errp); }
static int phylink_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id) { struct phylink *pl = upstream; __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, }; struct phylink_link_state config; phy_interface_t iface; int mode, ret = 0; bool changed; u8 port; sfp_parse_support(pl->sfp_bus, id, support); port = sfp_parse_port(pl->sfp_bus, id, support); iface = sfp_parse_interface(pl->sfp_bus, id); WARN_ON(!lockdep_rtnl_is_held()); switch (iface) { case PHY_INTERFACE_MODE_SGMII: mode = MLO_AN_SGMII; break; case PHY_INTERFACE_MODE_1000BASEX: mode = MLO_AN_8023Z; break; default: return -EINVAL; } memset(&config, 0, sizeof(config)); linkmode_copy(config.advertising, support); config.interface = iface; config.speed = SPEED_UNKNOWN; config.duplex = DUPLEX_UNKNOWN; config.pause = MLO_PAUSE_AN; config.an_enabled = pl->link_config.an_enabled; /* Ignore errors if we're expecting a PHY to attach later */ ret = phylink_validate(pl, support, &config); if (ret) { netdev_err(pl->netdev, "validation of %s/%s with support %*pb failed: %d\n", phylink_an_mode_str(mode), phy_modes(config.interface), __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret); return ret; } netdev_dbg(pl->netdev, "requesting link mode %s/%s with support %*pb\n", phylink_an_mode_str(mode), phy_modes(config.interface), __ETHTOOL_LINK_MODE_MASK_NBITS, support); if (mode == MLO_AN_8023Z && pl->phydev) return -EINVAL; changed = !bitmap_equal(pl->supported, support, __ETHTOOL_LINK_MODE_MASK_NBITS); if (changed) { linkmode_copy(pl->supported, support); linkmode_copy(pl->link_config.advertising, config.advertising); } if (pl->link_an_mode != mode || pl->link_config.interface != config.interface) { pl->link_config.interface = config.interface; pl->link_an_mode = mode; changed = true; netdev_info(pl->netdev, "switched to %s/%s link mode\n", phylink_an_mode_str(mode), phy_modes(config.interface)); } pl->link_port = port; if (changed && !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) phylink_mac_config(pl, &pl->link_config); return ret; }
/* Returns true if 'a' and 'b' are the same: either both null or both the same * 4096-bit bitmap. * * (We assume that a nonnull bitmap is not all 0-bits.) */ bool vlan_bitmap_equal(const unsigned long *a, const unsigned long *b) { return (!a && !b) || (a && b && bitmap_equal(a, b, 4096)); }
CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa, CpuModelInfo *infob, Error **errp) { CpuModelCompareResult feat_result, gen_result; CpuModelCompareInfo *compare_info; S390FeatBitmap missing, added; S390CPUModel modela, modelb; /* convert both models to our internal representation */ cpu_model_from_info(&modela, infoa, errp); if (*errp) { return NULL; } cpu_model_from_info(&modelb, infob, errp); if (*errp) { return NULL; } compare_info = g_malloc0(sizeof(*compare_info)); /* check the cpu generation and ga level */ if (modela.def->gen == modelb.def->gen) { if (modela.def->ec_ga == modelb.def->ec_ga) { /* ec and corresponding bc are identical */ gen_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL; } else if (modela.def->ec_ga < modelb.def->ec_ga) { gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET; } else { gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET; } } else if (modela.def->gen < modelb.def->gen) { gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET; } else { gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET; } if (gen_result != CPU_MODEL_COMPARE_RESULT_IDENTICAL) { /* both models cannot be made identical */ list_add_feat("type", &compare_info->responsible_properties); } /* check the feature set */ if (bitmap_equal(modela.features, modelb.features, S390_FEAT_MAX)) { feat_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL; } else { bitmap_andnot(missing, modela.features, modelb.features, S390_FEAT_MAX); s390_feat_bitmap_to_ascii(missing, &compare_info->responsible_properties, list_add_feat); bitmap_andnot(added, modelb.features, modela.features, S390_FEAT_MAX); s390_feat_bitmap_to_ascii(added, &compare_info->responsible_properties, list_add_feat); if (bitmap_empty(missing, S390_FEAT_MAX)) { feat_result = CPU_MODEL_COMPARE_RESULT_SUBSET; } else if (bitmap_empty(added, S390_FEAT_MAX)) { feat_result = CPU_MODEL_COMPARE_RESULT_SUPERSET; } else { feat_result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE; } } /* combine the results */ if (gen_result == feat_result) { compare_info->result = gen_result; } else if (feat_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) { compare_info->result = gen_result; } else if (gen_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) { compare_info->result = feat_result; } else { compare_info->result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE; } return compare_info; }
static int phylink_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id) { struct phylink *pl = upstream; __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, }; struct phylink_link_state config; phy_interface_t iface; int ret = 0; bool changed; u8 port; ASSERT_RTNL(); sfp_parse_support(pl->sfp_bus, id, support); port = sfp_parse_port(pl->sfp_bus, id, support); memset(&config, 0, sizeof(config)); linkmode_copy(config.advertising, support); config.interface = PHY_INTERFACE_MODE_NA; config.speed = SPEED_UNKNOWN; config.duplex = DUPLEX_UNKNOWN; config.pause = MLO_PAUSE_AN; config.an_enabled = pl->link_config.an_enabled; /* Ignore errors if we're expecting a PHY to attach later */ ret = phylink_validate(pl, support, &config); if (ret) { netdev_err(pl->netdev, "validation with support %*pb failed: %d\n", __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret); return ret; } iface = sfp_select_interface(pl->sfp_bus, id, config.advertising); if (iface == PHY_INTERFACE_MODE_NA) { netdev_err(pl->netdev, "selection of interface failed, advertisement %*pb\n", __ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising); return -EINVAL; } config.interface = iface; ret = phylink_validate(pl, support, &config); if (ret) { netdev_err(pl->netdev, "validation of %s/%s with support %*pb failed: %d\n", phylink_an_mode_str(MLO_AN_INBAND), phy_modes(config.interface), __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret); return ret; } netdev_dbg(pl->netdev, "requesting link mode %s/%s with support %*pb\n", phylink_an_mode_str(MLO_AN_INBAND), phy_modes(config.interface), __ETHTOOL_LINK_MODE_MASK_NBITS, support); if (phy_interface_mode_is_8023z(iface) && pl->phydev) return -EINVAL; changed = !bitmap_equal(pl->supported, support, __ETHTOOL_LINK_MODE_MASK_NBITS); if (changed) { linkmode_copy(pl->supported, support); linkmode_copy(pl->link_config.advertising, config.advertising); } if (pl->link_an_mode != MLO_AN_INBAND || pl->link_config.interface != config.interface) { pl->link_config.interface = config.interface; pl->link_an_mode = MLO_AN_INBAND; changed = true; netdev_info(pl->netdev, "switched to %s/%s link mode\n", phylink_an_mode_str(MLO_AN_INBAND), phy_modes(config.interface)); } pl->link_port = port; if (changed && !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) phylink_mac_config(pl, &pl->link_config); return ret; }