mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
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>
This commit is contained in:
committed by
Christian Brauner
parent
f2e467a482
commit
e7b840fd49
@@ -637,9 +637,8 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915,
|
||||
{
|
||||
struct drm_i915_gem_object *obj;
|
||||
struct file *file;
|
||||
const struct address_space_operations *aops;
|
||||
loff_t pos;
|
||||
int err;
|
||||
loff_t pos = 0;
|
||||
ssize_t err;
|
||||
|
||||
GEM_WARN_ON(IS_DGFX(i915));
|
||||
obj = i915_gem_object_create_shmem(i915, round_up(size, PAGE_SIZE));
|
||||
@@ -649,29 +648,15 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915,
|
||||
GEM_BUG_ON(obj->write_domain != I915_GEM_DOMAIN_CPU);
|
||||
|
||||
file = obj->base.filp;
|
||||
aops = file->f_mapping->a_ops;
|
||||
pos = 0;
|
||||
do {
|
||||
unsigned int len = min_t(typeof(size), size, PAGE_SIZE);
|
||||
struct folio *folio;
|
||||
void *fsdata;
|
||||
err = kernel_write(file, data, size, &pos);
|
||||
|
||||
err = aops->write_begin(file, file->f_mapping, pos, len,
|
||||
&folio, &fsdata);
|
||||
if (err < 0)
|
||||
goto fail;
|
||||
if (err < 0)
|
||||
goto fail;
|
||||
|
||||
memcpy_to_folio(folio, offset_in_folio(folio, pos), data, len);
|
||||
|
||||
err = aops->write_end(file, file->f_mapping, pos, len, len,
|
||||
folio, fsdata);
|
||||
if (err < 0)
|
||||
goto fail;
|
||||
|
||||
size -= len;
|
||||
data += len;
|
||||
pos += len;
|
||||
} while (size);
|
||||
if (err != size) {
|
||||
err = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user