Skip to content

Commit 93bb8e3

Browse files
kwilczynskigregkh
authored andcommitted
sysfs: Invoke iomem_get_mapping() from the sysfs open callback
Defer invocation of the iomem_get_mapping() to the sysfs open callback so that it can be executed as needed when the binary sysfs object has been accessed. To do that, convert the "mapping" member of the struct bin_attribute from a pointer to the struct address_space into a function pointer with a signature that requires the same return type, and then updates the sysfs_kf_bin_open() to invoke provided function should the function pointer be valid. Also, convert every invocation of iomem_get_mapping() into a function pointer assignment, therefore allowing for the iomem_get_mapping() invocation to be deferred to when the sysfs open callback runs. Thus, this change removes the need for the fs_initcalls to complete before any other sub-system that uses the iomem_get_mapping() would be able to invoke it safely without leading to a failure and an Oops related to an invalid iomem_get_mapping() access. Suggested-by: Dan Williams <[email protected]> Reviewed-by: Dan Williams <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Signed-off-by: Dan Williams <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ff11764 commit 93bb8e3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ void pci_create_legacy_files(struct pci_bus *b)
965965
b->legacy_io->read = pci_read_legacy_io;
966966
b->legacy_io->write = pci_write_legacy_io;
967967
b->legacy_io->mmap = pci_mmap_legacy_io;
968-
b->legacy_io->mapping = iomem_get_mapping();
968+
b->legacy_io->mapping = iomem_get_mapping;
969969
pci_adjust_legacy_attr(b, pci_mmap_io);
970970
error = device_create_bin_file(&b->dev, b->legacy_io);
971971
if (error)
@@ -978,7 +978,7 @@ void pci_create_legacy_files(struct pci_bus *b)
978978
b->legacy_mem->size = 1024*1024;
979979
b->legacy_mem->attr.mode = 0600;
980980
b->legacy_mem->mmap = pci_mmap_legacy_mem;
981-
b->legacy_io->mapping = iomem_get_mapping();
981+
b->legacy_io->mapping = iomem_get_mapping;
982982
pci_adjust_legacy_attr(b, pci_mmap_mem);
983983
error = device_create_bin_file(&b->dev, b->legacy_mem);
984984
if (error)
@@ -1195,7 +1195,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
11951195
}
11961196
}
11971197
if (res_attr->mmap)
1198-
res_attr->mapping = iomem_get_mapping();
1198+
res_attr->mapping = iomem_get_mapping;
11991199
res_attr->attr.name = res_attr_name;
12001200
res_attr->attr.mode = 0600;
12011201
res_attr->size = pci_resource_len(pdev, num);

fs/sysfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static int sysfs_kf_bin_open(struct kernfs_open_file *of)
175175
struct bin_attribute *battr = of->kn->priv;
176176

177177
if (battr->mapping)
178-
of->file->f_mapping = battr->mapping;
178+
of->file->f_mapping = battr->mapping();
179179

180180
return 0;
181181
}

include/linux/sysfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct bin_attribute {
176176
struct attribute attr;
177177
size_t size;
178178
void *private;
179-
struct address_space *mapping;
179+
struct address_space *(*mapping)(void);
180180
ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
181181
char *, loff_t, size_t);
182182
ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,

0 commit comments

Comments
 (0)