Lines Matching +full:deep +full:- +full:touch
1 // SPDX-License-Identifier: GPL-2.0
55 switch (entry->type) { in tb_property_entry_valid()
59 if (entry->length > block_len) in tb_property_entry_valid()
61 if (entry->value + entry->length > block_len) in tb_property_entry_valid()
66 if (entry->length != 1) in tb_property_entry_valid()
88 strcpy(property->key, key); in tb_property_alloc()
89 property->type = type; in tb_property_alloc()
90 INIT_LIST_HEAD(&property->list); in tb_property_alloc()
108 property = tb_property_alloc(key, entry->type); in tb_property_parse()
112 property->length = entry->length; in tb_property_parse()
114 switch (property->type) { in tb_property_parse()
116 dir = __tb_property_parse_dir(block, block_len, entry->value, in tb_property_parse()
117 entry->length, false); in tb_property_parse()
122 property->value.dir = dir; in tb_property_parse()
126 property->value.data = kcalloc(property->length, sizeof(u32), in tb_property_parse()
128 if (!property->value.data) { in tb_property_parse()
132 parse_dwdata(property->value.data, block + entry->value, in tb_property_parse()
133 entry->length); in tb_property_parse()
137 property->value.text = kcalloc(property->length, sizeof(u32), in tb_property_parse()
139 if (!property->value.text) { in tb_property_parse()
143 parse_dwdata(property->value.text, block + entry->value, in tb_property_parse()
144 entry->length); in tb_property_parse()
146 property->value.text[property->length * 4 - 1] = '\0'; in tb_property_parse()
150 property->value.immediate = entry->value; in tb_property_parse()
154 property->type = TB_PROPERTY_TYPE_UNKNOWN; in tb_property_parse()
177 dir->uuid = kmemdup(&block[dir_offset], sizeof(*dir->uuid), in __tb_property_parse_dir()
179 if (!dir->uuid) { in __tb_property_parse_dir()
184 content_len = dir_len - 4; /* Length includes UUID */ in __tb_property_parse_dir()
190 INIT_LIST_HEAD(&dir->properties); in __tb_property_parse_dir()
201 list_add_tail(&property->list, &dir->properties); in __tb_property_parse_dir()
208 * tb_property_parse_dir() - Parses properties from given property block
226 if (rootdir->magic != TB_PROPERTY_ROOTDIR_MAGIC) in tb_property_parse_dir()
228 if (rootdir->length > block_len) in tb_property_parse_dir()
231 return __tb_property_parse_dir(block, block_len, 0, rootdir->length, in tb_property_parse_dir()
236 * tb_property_create_dir() - Creates new property directory
250 INIT_LIST_HEAD(&dir->properties); in tb_property_create_dir()
252 dir->uuid = kmemdup(uuid, sizeof(*dir->uuid), GFP_KERNEL); in tb_property_create_dir()
253 if (!dir->uuid) { in tb_property_create_dir()
265 switch (property->type) { in tb_property_free()
267 tb_property_free_dir(property->value.dir); in tb_property_free()
271 kfree(property->value.data); in tb_property_free()
275 kfree(property->value.text); in tb_property_free()
286 * tb_property_free_dir() - Release memory allocated for property directory
300 list_for_each_entry_safe(property, tmp, &dir->properties, list) { in tb_property_free_dir()
301 list_del(&property->list); in tb_property_free_dir()
304 kfree(dir->uuid); in tb_property_free_dir()
315 if (dir->uuid) in tb_property_dir_length()
316 len += sizeof(*dir->uuid) / 4; in tb_property_dir_length()
320 list_for_each_entry(property, &dir->properties, list) { in tb_property_dir_length()
323 switch (property->type) { in tb_property_dir_length()
327 property->value.dir, recurse, data_len); in tb_property_dir_length()
337 *data_len += property->length; in tb_property_dir_length()
362 * +----------+ <-- start_offset in __tb_property_format_dir()
363 * | header | <-- root directory header in __tb_property_format_dir()
364 * +----------+ --- in __tb_property_format_dir()
365 * | entry 0 | -^--------------------. in __tb_property_format_dir()
366 * +----------+ | | in __tb_property_format_dir()
367 * | entry 1 | -|--------------------|--. in __tb_property_format_dir()
368 * +----------+ | | | in __tb_property_format_dir()
369 * | entry 2 | -|-----------------. | | in __tb_property_format_dir()
370 * +----------+ | | | | in __tb_property_format_dir()
374 * +----------+ | | | | in __tb_property_format_dir()
376 * +----------+ <-- data_offset | | | in __tb_property_format_dir()
377 * | data 0 | <------------------|--' | in __tb_property_format_dir()
378 * +----------+ | | in __tb_property_format_dir()
379 * | data 1 | <------------------|-----' in __tb_property_format_dir()
380 * +----------+ | in __tb_property_format_dir()
382 * +----------+ <-- dir_end <------' in __tb_property_format_dir()
383 * | UUID | <-- directory UUID (child directory) in __tb_property_format_dir()
384 * +----------+ in __tb_property_format_dir()
386 * +----------+ in __tb_property_format_dir()
388 * +----------+ in __tb_property_format_dir()
392 * +----------+ in __tb_property_format_dir()
394 * +----------+ in __tb_property_format_dir()
396 * +----------+ in __tb_property_format_dir()
407 return -EINVAL; in __tb_property_format_dir()
409 return -EINVAL; in __tb_property_format_dir()
412 if (dir->uuid) { in __tb_property_format_dir()
416 memcpy(pe->uuid, dir->uuid, sizeof(pe->uuid)); in __tb_property_format_dir()
417 entry = pe->entries; in __tb_property_format_dir()
422 re->magic = TB_PROPERTY_ROOTDIR_MAGIC; in __tb_property_format_dir()
423 re->length = dir_len - sizeof(*re) / 4; in __tb_property_format_dir()
424 entry = re->entries; in __tb_property_format_dir()
427 list_for_each_entry(property, &dir->properties, list) { in __tb_property_format_dir()
430 format_dwdata(entry, property->key, 2); in __tb_property_format_dir()
431 entry->type = property->type; in __tb_property_format_dir()
433 switch (property->type) { in __tb_property_format_dir()
435 child = property->value.dir; in __tb_property_format_dir()
440 entry->length = tb_property_dir_length(child, false, in __tb_property_format_dir()
442 entry->value = dir_end; in __tb_property_format_dir()
447 format_dwdata(&block[data_offset], property->value.data, in __tb_property_format_dir()
448 property->length); in __tb_property_format_dir()
449 entry->length = property->length; in __tb_property_format_dir()
450 entry->value = data_offset; in __tb_property_format_dir()
451 data_offset += entry->length; in __tb_property_format_dir()
455 format_dwdata(&block[data_offset], property->value.text, in __tb_property_format_dir()
456 property->length); in __tb_property_format_dir()
457 entry->length = property->length; in __tb_property_format_dir()
458 entry->value = data_offset; in __tb_property_format_dir()
459 data_offset += entry->length; in __tb_property_format_dir()
463 entry->length = property->length; in __tb_property_format_dir()
464 entry->value = property->value.immediate; in __tb_property_format_dir()
478 * tb_property_format_dir() - Formats directory to the packed XDomain format
505 * tb_property_copy_dir() - Take a deep copy of directory
508 * This function takes a deep copy of @dir and returns back the copy. In
520 d = tb_property_create_dir(dir->uuid); in tb_property_copy_dir()
524 list_for_each_entry(property, &dir->properties, list) { in tb_property_copy_dir()
527 p = tb_property_alloc(property->key, property->type); in tb_property_copy_dir()
531 p->length = property->length; in tb_property_copy_dir()
533 switch (property->type) { in tb_property_copy_dir()
535 p->value.dir = tb_property_copy_dir(property->value.dir); in tb_property_copy_dir()
536 if (!p->value.dir) in tb_property_copy_dir()
541 p->value.data = kmemdup(property->value.data, in tb_property_copy_dir()
542 property->length * 4, in tb_property_copy_dir()
544 if (!p->value.data) in tb_property_copy_dir()
549 p->value.text = kzalloc(p->length * 4, GFP_KERNEL); in tb_property_copy_dir()
550 if (!p->value.text) in tb_property_copy_dir()
552 strcpy(p->value.text, property->value.text); in tb_property_copy_dir()
556 p->value.immediate = property->value.immediate; in tb_property_copy_dir()
563 list_add_tail(&p->list, &d->properties); in tb_property_copy_dir()
576 * tb_property_add_immediate() - Add immediate property to directory
587 return -EINVAL; in tb_property_add_immediate()
591 return -ENOMEM; in tb_property_add_immediate()
593 property->length = 1; in tb_property_add_immediate()
594 property->value.immediate = value; in tb_property_add_immediate()
596 list_add_tail(&property->list, &parent->properties); in tb_property_add_immediate()
602 * tb_property_add_data() - Adds arbitrary data property to directory
618 return -EINVAL; in tb_property_add_data()
622 return -ENOMEM; in tb_property_add_data()
624 property->length = size / 4; in tb_property_add_data()
625 property->value.data = kzalloc(size, GFP_KERNEL); in tb_property_add_data()
626 if (!property->value.data) { in tb_property_add_data()
628 return -ENOMEM; in tb_property_add_data()
631 memcpy(property->value.data, buf, buflen); in tb_property_add_data()
633 list_add_tail(&property->list, &parent->properties); in tb_property_add_data()
639 * tb_property_add_text() - Adds string property to directory
654 return -EINVAL; in tb_property_add_text()
658 return -ENOMEM; in tb_property_add_text()
660 property->length = size / 4; in tb_property_add_text()
661 property->value.text = kzalloc(size, GFP_KERNEL); in tb_property_add_text()
662 if (!property->value.text) { in tb_property_add_text()
664 return -ENOMEM; in tb_property_add_text()
667 strcpy(property->value.text, text); in tb_property_add_text()
669 list_add_tail(&property->list, &parent->properties); in tb_property_add_text()
675 * tb_property_add_dir() - Adds a directory to the parent directory
686 return -EINVAL; in tb_property_add_dir()
690 return -ENOMEM; in tb_property_add_dir()
692 property->value.dir = dir; in tb_property_add_dir()
694 list_add_tail(&property->list, &parent->properties); in tb_property_add_dir()
700 * tb_property_remove() - Removes property from a parent directory
704 * touch the object after call to this function.
708 list_del(&property->list); in tb_property_remove()
714 * tb_property_find() - Find a property from a directory
720 * into sub-directories. Returns %NULL if the property was not found.
727 list_for_each_entry(property, &dir->properties, list) { in tb_property_find()
728 if (property->type == type && !strcmp(property->key, key)) in tb_property_find()
737 * tb_property_get_next() - Get next property from directory
745 if (list_is_last(&prev->list, &dir->properties)) in tb_property_get_next()
749 return list_first_entry_or_null(&dir->properties, struct tb_property, in tb_property_get_next()