mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 19:08:57 +09:00
ANDROID: dma-buf: don't re-purpose kobject as work_struct
The commit 5aec776ef8 ("BACKPORT: ANDROID: dma-buf: Move sysfs work
out of DMA-BUF export path) re-purposed kobject as work_struct temporarily
to create the sysfs entries asynchronously. The author knows what he is
doing and rightly added a build assert if kobject struct size is smaller than
the work_struct size. We are hitting this build assert on a non-GKI platform
where CONFIG_ANDROID_KABI_RESERVE is not set. Fix this problem by allocating
a new union with dma_buf_sysfs_entry structure and temporary structure as
members. We only end up allocating more memory (because of union) only when
kobject size is smaller than work_struct which the original patch any way
assumed would never be true.
Bug: 261818147
Change-Id: Ifb089bf80d8a3a44ece9f05fc0b99ee76cb11645
Signed-off-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
This commit is contained in:
committed by
Treehugger Robot
parent
eddb2f39cd
commit
ce18af9b5d
@@ -142,15 +142,21 @@ void dma_buf_uninit_sysfs_statistics(void)
|
|||||||
kset_unregister(dma_buf_stats_kset);
|
kset_unregister(dma_buf_stats_kset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct dma_buf_create_sysfs_entry {
|
||||||
|
struct dma_buf *dmabuf;
|
||||||
|
struct work_struct work;
|
||||||
|
};
|
||||||
|
|
||||||
|
union dma_buf_create_sysfs_work_entry {
|
||||||
|
struct dma_buf_create_sysfs_entry create_entry;
|
||||||
|
struct dma_buf_sysfs_entry sysfs_entry;
|
||||||
|
};
|
||||||
|
|
||||||
static void sysfs_add_workfn(struct work_struct *work)
|
static void sysfs_add_workfn(struct work_struct *work)
|
||||||
{
|
{
|
||||||
/* The ABI would have to change for this to be false, but let's be paranoid. */
|
struct dma_buf_create_sysfs_entry *create_entry =
|
||||||
_Static_assert(sizeof(struct kobject) >= sizeof(struct work_struct),
|
container_of(work, struct dma_buf_create_sysfs_entry, work);
|
||||||
"kobject is smaller than work_struct");
|
struct dma_buf *dmabuf = create_entry->dmabuf;
|
||||||
|
|
||||||
struct dma_buf_sysfs_entry *sysfs_entry =
|
|
||||||
container_of((struct kobject *)work, struct dma_buf_sysfs_entry, kobj);
|
|
||||||
struct dma_buf *dmabuf = sysfs_entry->dmabuf;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A dmabuf is ref-counted via its file member. If this handler holds the only
|
* A dmabuf is ref-counted via its file member. If this handler holds the only
|
||||||
@@ -161,6 +167,7 @@ static void sysfs_add_workfn(struct work_struct *work)
|
|||||||
* is released, and that can't happen until the end of this function.
|
* is released, and that can't happen until the end of this function.
|
||||||
*/
|
*/
|
||||||
if (file_count(dmabuf->file) > 1) {
|
if (file_count(dmabuf->file) > 1) {
|
||||||
|
dmabuf->sysfs_entry->dmabuf = dmabuf;
|
||||||
/*
|
/*
|
||||||
* kobject_init_and_add expects kobject to be zero-filled, but we have populated it
|
* kobject_init_and_add expects kobject to be zero-filled, but we have populated it
|
||||||
* to trigger this work function.
|
* to trigger this work function.
|
||||||
@@ -185,8 +192,8 @@ static void sysfs_add_workfn(struct work_struct *work)
|
|||||||
|
|
||||||
int dma_buf_stats_setup(struct dma_buf *dmabuf)
|
int dma_buf_stats_setup(struct dma_buf *dmabuf)
|
||||||
{
|
{
|
||||||
struct dma_buf_sysfs_entry *sysfs_entry;
|
struct dma_buf_create_sysfs_entry *create_entry;
|
||||||
struct work_struct *work;
|
union dma_buf_create_sysfs_work_entry *work_entry;
|
||||||
|
|
||||||
if (!dmabuf || !dmabuf->file)
|
if (!dmabuf || !dmabuf->file)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -196,21 +203,18 @@ int dma_buf_stats_setup(struct dma_buf *dmabuf)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sysfs_entry = kmalloc(sizeof(struct dma_buf_sysfs_entry), GFP_KERNEL);
|
work_entry = kmalloc(sizeof(union dma_buf_create_sysfs_work_entry), GFP_KERNEL);
|
||||||
if (!sysfs_entry)
|
if (!work_entry)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
sysfs_entry->dmabuf = dmabuf;
|
dmabuf->sysfs_entry = &work_entry->sysfs_entry;
|
||||||
dmabuf->sysfs_entry = sysfs_entry;
|
|
||||||
|
|
||||||
/*
|
create_entry = &work_entry->create_entry;
|
||||||
* The use of kobj as a work_struct is an ugly hack
|
create_entry->dmabuf = dmabuf;
|
||||||
* to avoid an ABI break in this frozen kernel.
|
|
||||||
*/
|
INIT_WORK(&create_entry->work, sysfs_add_workfn);
|
||||||
work = (struct work_struct *)&dmabuf->sysfs_entry->kobj;
|
|
||||||
INIT_WORK(work, sysfs_add_workfn);
|
|
||||||
get_dma_buf(dmabuf); /* This reference will be dropped in sysfs_add_workfn. */
|
get_dma_buf(dmabuf); /* This reference will be dropped in sysfs_add_workfn. */
|
||||||
schedule_work(work);
|
schedule_work(&create_entry->work);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user