def METHOD_NAME(prog: Program) -> Iterator[Object]:
    try:
        devices, class_in_device_private = prog.cache["_for_each_block_device"]
    except KeyError:
        devices = _class_to_subsys(
            prog["block_class"].address_of_()
        ).klist_devices.k_list.address_of_()
        # Linux kernel commit 570d0200123f ("driver core: move
        # device->knode_class to device_private") (in v5.1) moved the list
        # node.
        class_in_device_private = prog.type("struct device_private").has_member(
            "knode_class"
        )
        prog.cache["_for_each_block_device"] = devices, class_in_device_private
    if class_in_device_private:
        for device_private in list_for_each_entry(
            "struct device_private", devices, "knode_class.n_node"
        ):
            yield device_private.device
    else:
        yield from list_for_each_entry("struct device", devices, "knode_class.n_node")