Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/i915: Use kernel_write() in shmem object create

Replace the write_begin/write_end loop in
i915_gem_object_create_shmem_from_data() with call to kernel_write().

This function initializes shmem-backed GEM objects. kernel_write()
simplifies the code by removing manual folio handling.

Part of a series refactoring address_space_operations write_begin and
write_end callbacks to use struct kiocb for passing write context and
flags.

Signed-off-by: Taotao Chen <chentaotao@didiglobal.com>
Link: https://lore.kernel.org/20250716093559.217344-2-chentaotao@didiglobal.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Taotao Chen and committed by
Christian Brauner
e7b840fd f2e467a4

+9 -24
+9 -24
drivers/gpu/drm/i915/gem/i915_gem_shmem.c
··· 637 637 { 638 638 struct drm_i915_gem_object *obj; 639 639 struct file *file; 640 - const struct address_space_operations *aops; 641 - loff_t pos; 642 - int err; 640 + loff_t pos = 0; 641 + ssize_t err; 643 642 644 643 GEM_WARN_ON(IS_DGFX(i915)); 645 644 obj = i915_gem_object_create_shmem(i915, round_up(size, PAGE_SIZE)); ··· 648 649 GEM_BUG_ON(obj->write_domain != I915_GEM_DOMAIN_CPU); 649 650 650 651 file = obj->base.filp; 651 - aops = file->f_mapping->a_ops; 652 - pos = 0; 653 - do { 654 - unsigned int len = min_t(typeof(size), size, PAGE_SIZE); 655 - struct folio *folio; 656 - void *fsdata; 652 + err = kernel_write(file, data, size, &pos); 657 653 658 - err = aops->write_begin(file, file->f_mapping, pos, len, 659 - &folio, &fsdata); 660 - if (err < 0) 661 - goto fail; 654 + if (err < 0) 655 + goto fail; 662 656 663 - memcpy_to_folio(folio, offset_in_folio(folio, pos), data, len); 664 - 665 - err = aops->write_end(file, file->f_mapping, pos, len, len, 666 - folio, fsdata); 667 - if (err < 0) 668 - goto fail; 669 - 670 - size -= len; 671 - data += len; 672 - pos += len; 673 - } while (size); 657 + if (err != size) { 658 + err = -EIO; 659 + goto fail; 660 + } 674 661 675 662 return obj; 676 663