mei: fix mei_device lifetime
Subsystems (2)
Alexander Usyskin
maintainerv3 cover mei: fix mei_device lifetime
mei_device data structure is allocated using devm_* functions and hooked to the parent device.
It works for client systems where parent device is pci one. When parent device is auxiliary bus device produced by graphics driver, the parent can be destroyed before child and on the way it cleans all allocated memory.
This leads to use-after-free if mei character device is opened when parent device is destroyed.
Connect mei_device structure lifteme to mei class device lifetime by adding mei_device free to class device remove callback. Decouple character device lifetime from parwnt structure lifetime.
As dev pointer in mei_device structure is converted to non-pointer device all dev_* calls should be touched in this patch series.
V2: Make cdev patches first to avoid double refcounting
in the middle of the series.
Replace manual refcount with special device.
V3: Use existing class device by Greg's insight, thanks!
Alexander Usyskin (5):
mei: set parent for char device
mei: make char device control its own lifetime
mei: bus: use cldev in prints
mei: more prints with client prefix
mei: hook mei_device on class device
drivers/misc/mei/bus-fixup.c | 16 ++-- drivers/misc/mei/bus.c | 42 +++++----- drivers/misc/mei/client.c | 82 +++++++++---------- drivers/misc/mei/client.h | 6 +- drivers/misc/mei/dma-ring.c | 8 +- drivers/misc/mei/gsc-me.c | 16 ++-- drivers/misc/mei/hbm.c | 135 +++++++++++++++----------------- drivers/misc/mei/hw-me.c | 100 +++++++++++------------ drivers/misc/mei/hw-txe.c | 60 +++++++------- drivers/misc/mei/init.c | 47 ++++++----- drivers/misc/mei/interrupt.c | 47 ++++++----- drivers/misc/mei/main.c | 135 +++++++++++++++++++------------- drivers/misc/mei/mei_dev.h | 12 +-- drivers/misc/mei/pci-me.c | 20 ++--- drivers/misc/mei/pci-txe.c | 4 +- drivers/misc/mei/platform-vsc.c | 26 +++--- 16 files changed, 390 insertions(+), 366 deletions(-)
Signature · 1 line
2.43.0
Alexander Usyskin
maintainerPATCH v3 1/5 mei: set parent for char device
Connect char device to parent device to avoid
parent device unload while char device is
still held open by user-space.
--- drivers/misc/mei/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/mei/main.c +1 -0
@@ -1225,6 +1225,7 @@ int mei_register(struct mei_device *dev, struct device *parent) devno =MKDEV (MAJOR (mei_devt), dev->minor);cdev_init (&dev->cdev, &mei_fops); dev->cdev.owner = parent->driver->owner; +cdev_set_parent (&dev->cdev, &parent->kobj);/* Add the device */ ret =cdev_add (&dev->cdev, devno,1 );
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerRe: [char-misc-next v3 1/5] mei: set parent for char device
Quoted 3 lines · Alexander Usyskin
Connect char device to parent device to avoid
parent device unload while char device is
still held open by user-space.
Again, you have 72 columns to use, please use them :(
Greg Kroah-Hartman
maintainerRe: [char-misc-next v3 1/5] mei: set parent for char device
In reply to Alexander UsyskinQuoted 3 lines · Alexander Usyskin
Connect char device to parent device to avoid
parent device unload while char device is
still held open by user-space.
Again, this changelog text is not right. The parent pointer has nothing to do with "unloading" anything. It has everything to do with placing the device in the proper place in sysfs. So please show a before/after location of what happens when this patch is applied to make it more obvious what is happening here.
thanks,
greg k-h
Alexander Usyskin
maintainerPATCH v3 2/5 mei: make char device control its own lifetime
In reply to Alexander UsyskinAllocate character device dynamically and allow to control its own lifetime as it may outlive mei_device structure while character device closes after parent device is removed from the system.
--- drivers/misc/mei/main.c | 36 +++++++++++++++++++++++------------- drivers/misc/mei/mei_dev.h | 4 ++-- 2 files changed, 25 insertions(+), 15 deletions(-)
drivers/misc/mei/main.c +23 -13
@@ -51,7 +51,9 @@ static int mei_open(struct inode *inode, struct file *file)int err; - dev = container_of(inode->i_cdev, struct mei_device, cdev); + dev =idr_find (&mei_idr,iminor (inode)); +if (!dev) +return -ENODEV ;mutex_lock (&dev->device_lock);
@@ -1118,7 +1120,10 @@ void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state) dev->dev_state = state; - clsdev =class_find_device_by_devt (&mei_class, dev->cdev.dev); +if (!dev->cdev) +return ; + + clsdev =class_find_device_by_devt (&mei_class, dev->cdev->dev);if (clsdev) {sysfs_notify (&clsdev->kobj,NULL ,"dev_state" );put_device (clsdev);
@@ -1223,16 +1228,21 @@ int mei_register(struct mei_device *dev, struct device *parent)/* Fill in the data structures */ devno =MKDEV (MAJOR (mei_devt), dev->minor); -cdev_init (&dev->cdev, &mei_fops); - dev->cdev.owner = parent->driver->owner; -cdev_set_parent (&dev->cdev, &parent->kobj); + dev->cdev =cdev_alloc (); +if (!dev->cdev) { + ret = -ENOMEM ; + goto err; + } + dev->cdev->ops = &mei_fops; + dev->cdev->owner = parent->driver->owner; +cdev_set_parent (dev->cdev, &parent->kobj);/* Add the device */ - ret =cdev_add (&dev->cdev, devno,1 ); + ret =cdev_add (dev->cdev, devno,1 );if (ret) {dev_err (parent,"unable to add device %d:%d\n" ,MAJOR (mei_devt), dev->minor); - goto err_dev_add; + goto err_del_cdev; } clsdev = device_create_with_groups(&mei_class, parent, devno,
@@ -1243,16 +1253,16 @@ int mei_register(struct mei_device *dev, struct device *parent)dev_err (parent,"unable to create device %d:%d\n" ,MAJOR (mei_devt), dev->minor); ret =PTR_ERR (clsdev); - goto err_dev_create; + goto err_del_cdev; }mei_dbgfs_register (dev,dev_name (clsdev));return 0 ; -err_dev_create: -cdev_del (&dev->cdev); -err_dev_add: +err_del_cdev: +cdev_del (dev->cdev); +err:mei_minor_free (dev);return ret; }
@@ -1262,8 +1272,8 @@ void mei_deregister(struct mei_device *dev) {int devno; - devno = dev->cdev.dev; -cdev_del (&dev->cdev); + devno = dev->cdev->dev; +cdev_del (dev->cdev);mei_dbgfs_deregister (dev);
drivers/misc/mei/mei_dev.h +2 -2
@@ -471,7 +471,7 @@ struct mei_dev_timeouts {* struct mei_device - MEI private device struct * * @dev : device on a bus -* @cdev : character device +* @cdev : character device pointer * @minor : minor number allocated for device * * @write_list : write pending list
@@ -557,7 +557,7 @@ struct mei_dev_timeouts {*/ struct mei_device {struct device *dev; -struct cdev cdev; +struct cdev *cdev;int minor;struct list_head write_list;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerRe: [char-misc-next v3 2/5] mei: make char device control its own lifetime
Quoted 16 lines · Alexander Usyskin
Allocate character device dynamically and allow to control its own lifetime as it may outlive
mei_devicestructure while character device closes after parent device is removed from the system.Signed-off-by Alexander Usyskin <[email protected]>--- drivers/misc/mei/main.c | 36 +++++++++++++++++++++++------------- drivers/misc/mei/mei_dev.h | 4 ++-- 2 files changed, 25 insertions(+), 15 deletions(-)drivers/misc/mei/main.c +0
-0
drivers/misc/mei/main.c static int mei_open(struct inode *inode, struct file *file) · line 54
Quoted 5 lines
drivers/misc/mei/main.c +1
-1@@ -51,7 +51,9 @@ static int mei_open(struct inode *inode, struct file *file)int err; - dev = container_of(inode->i_cdev, struct mei_device, cdev); + dev =idr_find (&mei_idr,iminor (inode));
What keeps the device structure in this idr after it has been removed from the system before the char device is closed? Does the class device lifespan outlive this? It seems like it really isn't saved anywhere, but the release function accesses it, right?
Or is that a _different_ device pointer? How many different pointers/structures are associated with a struct mei_device now?
confused,
greg k-h
Usyskin, Alexander
maintainerRE: [char-misc-next v3 2/5] mei: make char device control its own lifetime
Quoted 32 lines
Subject: Re: [char-misc-next v3 2/5] mei: make char device control its own lifetime
drivers/misc/mei/main.c static int mei_open(struct inode *inode, struct file
Quoted 16 lines · Alexander Usyskin
Allocate character device dynamically and allow to control its own lifetime as it may outlive
mei_devicestructure while character device closes after parent device is removed from the system.Signed-off-by Alexander Usyskin <[email protected]>--- drivers/misc/mei/main.c | 36 +++++++++++++++++++++++------------- drivers/misc/mei/mei_dev.h | 4 ++-- 2 files changed, 25 insertions(+), 15 deletions(-)drivers/misc/mei/main.c +0
-0@@ -51,7 +51,9 @@ static int mei_open(struct inode *inode, struct file*file)
drivers/misc/mei/main.c static int mei_open(struct inode *inode, struct file *file) · line 54
Quoted 5 lines
drivers/misc/mei/main.c +1
-1int err; - dev = container_of(inode->i_cdev, struct mei_device, cdev); + dev =idr_find (&mei_idr,iminor (inode));What keeps the device structure in this idr after it has been removed from the system before the char device is closed? Does the class device lifespan outlive this? It seems like it really isn't saved anywhere, but the release function accesses it, right?
Quoted 3 lines
Or is that a _different_ device pointer? How many different pointers/structures are associated with a struct
mei_devicenow?
At this point in series mei_device still managed via parent device devm and this patch is not fixing that problem.
This patch fixes the problem where cdev outlives mei_device:
- We are calling put_device in mei_release that can free mei_device
- cdev calls put_ref on itself after mei_release exits
This is the reason we need cdev to manage it own lifetime.
The last patch in the series moves cdev parent to be the class device and manages mei_device structure lifetime on class device.
That make mei_device structure alive till the char device release last reference to the class device.
Seems like that I should merge this patch with last in this series for clarity. Will send next revision with this merged so you can review whole thing together.
- -
Thanks,
Sasha
Alexander Usyskin
maintainerPATCH v3 3/5 mei: bus: use cldev in prints
In reply to Alexander UsyskinFor unifomity, print using client device on bus
where possible.
--- drivers/misc/mei/bus-fixup.c | 10 +++++----- drivers/misc/mei/bus.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/misc/mei/bus-fixup.c +5 -5
@@ -463,14 +463,14 @@ static void mei_nfc(struct mei_cl_device *cldev)if (IS_ERR (cl)) { ret =PTR_ERR (cl); cl =NULL ; -dev_err (bus->dev,"nfc hook alloc failed %d\n" , ret); +dev_err (&cldev->dev,"nfc hook alloc failed %d\n" , ret); goto out; } me_cl =mei_me_cl_by_uuid (bus, &mei_nfc_info_guid);if (!me_cl) { ret = -ENOTTY ; -dev_err (bus->dev,"Cannot find nfc info %d\n" , ret); +dev_err (&cldev->dev,"Cannot find nfc info %d\n" , ret); goto out; }
@@ -496,13 +496,13 @@ static void mei_nfc(struct mei_cl_device *cldev) goto disconnect; } -dev_dbg (bus->dev,"nfc radio %s\n" , radio_name); +dev_dbg (&cldev->dev,"nfc radio %s\n" , radio_name);strscpy (cldev->name, radio_name,sizeof (cldev->name)); disconnect:mutex_lock (&bus->device_lock);if (mei_cl_disconnect (cl) <0 ) -dev_err (bus->dev,"Can't disconnect the NFC INFO ME\n" ); +dev_err (&cldev->dev,"Can't disconnect the NFC INFO ME\n" );mei_cl_flush_queues (cl,NULL );
@@ -515,7 +515,7 @@ static void mei_nfc(struct mei_cl_device *cldev)if (ret) cldev->do_match =0 ; -dev_dbg (bus->dev,"end of fixup match = %d\n" , cldev->do_match); +dev_dbg (&cldev->dev,"end of fixup match = %d\n" , cldev->do_match); }/**
drivers/misc/mei/bus.c +9 -9
@@ -875,14 +875,14 @@ int mei_cldev_disable(struct mei_cl_device *cldev)mei_cl_bus_vtag_free (cldev);if (!mei_cl_is_connected (cl)) { -dev_dbg (bus->dev,"Already disconnected\n" ); +dev_dbg (&cldev->dev,"Already disconnected\n" ); err =0 ; goto out; } err =mei_cl_disconnect (cl);if (err <0 ) -dev_err (bus->dev,"Could not disconnect from the ME client\n" ); +dev_err (&cldev->dev,"Could not disconnect from the ME client\n" ); out:/* Flush queues and remove any pending read unless we have mapped DMA */
@@ -935,7 +935,7 @@ ssize_t mei_cldev_send_gsc_command(struct mei_cl_device *cldev, cl = cldev->cl; bus = cldev->bus; -dev_dbg (bus->dev,"client_id %u, fence_id %u\n" , client_id, fence_id); +dev_dbg (&cldev->dev,"client_id %u, fence_id %u\n" , client_id, fence_id);if (!bus->hbm_f_gsc_supported)return -EOPNOTSUPP ;
@@ -983,11 +983,11 @@ ssize_t mei_cldev_send_gsc_command(struct mei_cl_device *cldev,/* send the message to GSC */ ret =__mei_cl_send (cl, (u8 *)ext_hdr, buf_sz,0 ,MEI_CL_IO_SGL );if (ret <0 ) { -dev_err (bus->dev,"__mei_cl_send failed, returned %zd\n" , ret); +dev_err (&cldev->dev,"__mei_cl_send failed, returned %zd\n" , ret); goto end; }if (ret != buf_sz) { -dev_err (bus->dev,"__mei_cl_send returned %zd instead of expected %zd\n" , +dev_err (&cldev->dev,"__mei_cl_send returned %zd instead of expected %zd\n" , ret, buf_sz); ret = -EIO ; goto end;
@@ -997,7 +997,7 @@ ssize_t mei_cldev_send_gsc_command(struct mei_cl_device *cldev, ret =__mei_cl_recv (cl, (u8 *)&rx_msg,sizeof (rx_msg),NULL ,MEI_CL_IO_SGL ,0 );if (ret !=sizeof (rx_msg)) { -dev_err (bus->dev,"__mei_cl_recv returned %zd instead of expected %zd\n" , +dev_err (&cldev->dev,"__mei_cl_recv returned %zd instead of expected %zd\n" , ret,sizeof (rx_msg));if (ret >=0 ) ret = -EIO ;
@@ -1006,13 +1006,13 @@ ssize_t mei_cldev_send_gsc_command(struct mei_cl_device *cldev,/* check rx_msg.client_id and rx_msg.fence_id match the ones we send */ if (rx_msg.client_id != client_id || rx_msg.fence_id != fence_id) { -dev_err (bus->dev,"received client_id/fence_id %u/%u instead of %u/%u sent\n" , +dev_err (&cldev->dev,"received client_id/fence_id %u/%u instead of %u/%u sent\n" , rx_msg.client_id, rx_msg.fence_id, client_id, fence_id); ret = -EFAULT ; goto end; } -dev_dbg (bus->dev,"gsc command: successfully written %u bytes\n" , rx_msg.written); +dev_dbg (&cldev->dev,"gsc command: successfully written %u bytes\n" , rx_msg.written); ret = rx_msg.written; end:
@@ -1399,7 +1399,7 @@ static int mei_cl_bus_dev_add(struct mei_cl_device *cldev) {int ret; -dev_dbg (cldev->bus->dev,"adding %pUL:%02X\n" , +dev_dbg (&cldev->dev,"adding %pUL:%02X\n" ,mei_me_cl_uuid (cldev->me_cl),mei_me_cl_ver (cldev->me_cl)); ret =device_add (&cldev->dev);
Signature · 1 line
2.43.0
Alexander Usyskin
maintainerPATCH v3 4/5 mei: more prints with client prefix
In reply to Alexander UsyskinUse client-aware print macro instead of usual device print in more places to expand debug-ability.
The client-aware print macro prefixes the usual device print with current connection endpoints.
--- drivers/misc/mei/hbm.c | 14 ++++----- drivers/misc/mei/interrupt.c | 2 +- drivers/misc/mei/main.c | 55 +++++++++++++++++------------------- 3 files changed, 34 insertions(+), 37 deletions(-)
drivers/misc/mei/hbm.c +7 -7
@@ -510,7 +510,7 @@ int mei_hbm_cl_notify_req(struct mei_device *dev, ret =mei_hbm_write_message (dev, &mei_hdr, &req);if (ret) -dev_err (dev->dev,"notify request failed: ret = %d\n" , ret); +cl_err (dev, cl,"notify request failed: ret = %d\n" , ret);return ret; }
@@ -626,7 +626,7 @@ int mei_hbm_cl_dma_map_req(struct mei_device *dev, struct mei_cl *cl) ret =mei_hbm_write_message (dev, &mei_hdr, &req);if (ret) -dev_err (dev->dev,"dma map request failed: ret = %d\n" , ret); +cl_err (dev, cl,"dma map request failed: ret = %d\n" , ret);return ret; }
@@ -654,7 +654,7 @@ int mei_hbm_cl_dma_unmap_req(struct mei_device *dev, struct mei_cl *cl) ret =mei_hbm_write_message (dev, &mei_hdr, &req);if (ret) -dev_err (dev->dev,"dma unmap request failed: ret = %d\n" , ret); +cl_err (dev, cl,"dma unmap request failed: ret = %d\n" , ret);return ret; }
@@ -679,10 +679,10 @@ static void mei_hbm_cl_dma_map_res(struct mei_device *dev,return ;if (res->status) { -dev_err (dev->dev,"cl dma map failed %d\n" , res->status); +cl_err (dev, cl,"cl dma map failed %d\n" , res->status); cl->status = -EFAULT ; }else { -dev_dbg (dev->dev,"cl dma map succeeded\n" ); +cl_dbg (dev, cl,"cl dma map succeeded\n" ); cl->dma_mapped =1 ; cl->status =0 ; }
@@ -709,10 +709,10 @@ static void mei_hbm_cl_dma_unmap_res(struct mei_device *dev,return ;if (res->status) { -dev_err (dev->dev,"cl dma unmap failed %d\n" , res->status); +cl_err (dev, cl,"cl dma unmap failed %d\n" , res->status); cl->status = -EFAULT ; }else { -dev_dbg (dev->dev,"cl dma unmap succeeded\n" ); +cl_dbg (dev, cl,"cl dma unmap succeeded\n" ); cl->dma_mapped =0 ; cl->status =0 ; }
drivers/misc/mei/interrupt.c +1 -1
@@ -35,7 +35,7 @@ void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list) cl = cb->cl;list_del_init (&cb->list); -dev_dbg (dev->dev,"completing call back.\n" ); +cl_dbg (dev, cl,"completing call back.\n" );mei_cl_complete (cl, cb); } }
drivers/misc/mei/main.c +26 -29
175 lines not on this page · raw message
Signature · 1 line
2.43.0
Alexander Usyskin
maintainerPATCH v3 5/5 mei: hook mei_device on class device
In reply to Alexander Usyskinmei_device lifetime was managed by devm procedure of parent device. But such memory is freed on device_del.Mei_device object is used by client object that may be alive after parent device is removed.
It may lead to use-after-free if discrete graphics driver unloads mei_gsc auxiliary device while user-space holds open handle to mei character device.
Connect mei_device structure lifteme to mei class device lifetime by adding mei_device free to class device remove callback.
Move exising parent device pointer to separate field in mei_device to avoid misuse.
Leave power management on parent device as we overwrite pci runtime pm procedure and user-space is expecting it there.
--- drivers/misc/mei/bus-fixup.c | 6 +- drivers/misc/mei/bus.c | 24 ++++--- drivers/misc/mei/client.c | 82 +++++++++++----------- drivers/misc/mei/client.h | 6 +- drivers/misc/mei/dma-ring.c | 8 +-- drivers/misc/mei/gsc-me.c | 16 ++--- drivers/misc/mei/hbm.c | 121 +++++++++++++++----------------- drivers/misc/mei/hw-me.c | 100 +++++++++++++------------- drivers/misc/mei/hw-txe.c | 60 ++++++++-------- drivers/misc/mei/init.c | 47 ++++++------- drivers/misc/mei/interrupt.c | 45 ++++++------ drivers/misc/mei/main.c | 47 +++++++++---- drivers/misc/mei/mei_dev.h | 8 ++- drivers/misc/mei/pci-me.c | 20 +++--- drivers/misc/mei/pci-txe.c | 4 +- drivers/misc/mei/platform-vsc.c | 26 +++---- 16 files changed, 318 insertions(+), 302 deletions(-)
drivers/misc/mei/bus-fixup.c +3 -3
@@ -386,7 +386,7 @@ static int mei_nfc_if_version(struct mei_cl *cl, ret =__mei_cl_send (cl, (u8 *)&cmd,sizeof (cmd),0 ,MEI_CL_IO_TX_BLOCKING );if (ret <0 ) { -dev_err (bus->dev,"Could not send IF version cmd ret = %d\n" , ret); +dev_err (&bus->dev,"Could not send IF version cmd ret = %d\n" , ret);return ret; }
@@ -401,14 +401,14 @@ static int mei_nfc_if_version(struct mei_cl *cl, bytes_recv =__mei_cl_recv (cl, (u8 *)reply, if_version_length, &vtag,0 ,0 );if (bytes_recv <0 || (size_t )bytes_recv < if_version_length) { -dev_err (bus->dev,"Could not read IF version ret = %d\n" , bytes_recv); +dev_err (&bus->dev,"Could not read IF version ret = %d\n" , bytes_recv); ret = -EIO ; goto err; }memcpy (ver, reply->data,sizeof (*ver)); -dev_info (bus->dev,"NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n" , +dev_info (&bus->dev,"NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n" , ver->fw_ivn, ver->vendor_id, ver->radio_type); err:
drivers/misc/mei/bus.c +14 -10
@@ -637,7 +637,7 @@ EXPORT_SYMBOL_GPL(mei_cldev_enabled);*/ static bool mei_cl_bus_module_get (struct mei_cl_device *cldev) { -return try_module_get (cldev->bus->dev->driver->owner); +return try_module_get (cldev->bus->parent->driver->owner); }/**
@@ -647,7 +647,7 @@ static bool mei_cl_bus_module_get(struct mei_cl_device *cldev)*/ static void mei_cl_bus_module_put (struct mei_cl_device *cldev) { -module_put (cldev->bus->dev->driver->owner); +module_put (cldev->bus->parent->driver->owner); }/**
@@ -1286,16 +1286,20 @@ static const struct bus_type mei_cl_bus_type = {static struct mei_device *mei_dev_bus_get (struct mei_device *bus) { -if (bus) -get_device (bus->dev); +if (bus) { +get_device (&bus->dev); +get_device (bus->parent); + }return bus; }static void mei_dev_bus_put (struct mei_device *bus) { -if (bus) -put_device (bus->dev); +if (bus) { +put_device (bus->parent); +put_device (&bus->dev); + } }static void mei_cl_bus_dev_release (struct device *dev)
@@ -1323,7 +1327,7 @@ static const struct device_type mei_cl_device_type = {static inline void mei_cl_bus_set_name (struct mei_cl_device *cldev) {dev_set_name (&cldev->dev,"%s-%pUl" , -dev_name (cldev->bus->dev), +dev_name (cldev->bus->parent),mei_me_cl_uuid (cldev->me_cl)); }
@@ -1352,7 +1356,7 @@ static struct mei_cl_device *mei_cl_bus_dev_alloc(struct mei_device *bus, }device_initialize (&cldev->dev); - cldev->dev.parent = bus->dev; + cldev->dev.parent = bus->parent; cldev->dev.bus = &mei_cl_bus_type; cldev->dev.type = &mei_cl_device_type; cldev->bus =mei_dev_bus_get (bus);
@@ -1487,7 +1491,7 @@ static void mei_cl_bus_dev_init(struct mei_device *bus,WARN_ON (!mutex_is_locked (&bus->cl_bus_lock)); -dev_dbg (bus->dev,"initializing %pUl" ,mei_me_cl_uuid (me_cl)); +dev_dbg (&bus->dev,"initializing %pUl" ,mei_me_cl_uuid (me_cl));if (me_cl->bus_added)return ;
@@ -1538,7 +1542,7 @@ static void mei_cl_bus_rescan(struct mei_device *bus) }mutex_unlock (&bus->cl_bus_lock); -dev_dbg (bus->dev,"rescan end" ); +dev_dbg (&bus->dev,"rescan end" ); }void mei_cl_bus_rescan_work (struct work_struct *work)
drivers/misc/mei/client.c +41 -41
229 lines not on this page · raw message
drivers/misc/mei/client.h +3 -3
@@ -275,12 +275,12 @@ int mei_cl_dma_unmap(struct mei_cl *cl, const struct file *fp);#define MEI_CL_PRM (cl) (cl)->host_client_id, mei_cl_me_id(cl) #define cl_dbg(dev, cl, format, arg...) \ - dev_dbg((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg) + dev_dbg(&(dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg) #define cl_warn(dev, cl, format, arg...) \ - dev_warn((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg) + dev_warn(&(dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg) #define cl_err(dev, cl, format, arg...) \ - dev_err((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg) + dev_err(&(dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)#endif /* _MEI_CLIENT_H_ */
drivers/misc/mei/dma-ring.c +4 -4
@@ -30,7 +30,7 @@ static int mei_dmam_dscr_alloc(struct mei_device *dev,if (dscr->vaddr)return 0 ; - dscr->vaddr =dmam_alloc_coherent (dev->dev, dscr->size, &dscr->daddr, + dscr->vaddr =dmam_alloc_coherent (dev->parent, dscr->size, &dscr->daddr,GFP_KERNEL );if (!dscr->vaddr)return -ENOMEM ;
@@ -50,7 +50,7 @@ static void mei_dmam_dscr_free(struct mei_device *dev,if (!dscr->vaddr)return ; -dmam_free_coherent (dev->dev, dscr->size, dscr->vaddr, dscr->daddr); +dmam_free_coherent (dev->parent, dscr->size, dscr->vaddr, dscr->daddr); dscr->vaddr =NULL ; }
@@ -177,7 +177,7 @@ void mei_dma_ring_read(struct mei_device *dev, unsigned char *buf, u32 len)if (WARN_ON (!ctrl))return ; -dev_dbg (dev->dev,"reading from dma %u bytes\n" , len); +dev_dbg (&dev->dev,"reading from dma %u bytes\n" , len);if (!len)return ;
@@ -254,7 +254,7 @@ void mei_dma_ring_write(struct mei_device *dev, unsigned char *buf, u32 len)if (WARN_ON (!ctrl))return ; -dev_dbg (dev->dev,"writing to dma %u bytes\n" , len); +dev_dbg (&dev->dev,"writing to dma %u bytes\n" , len); hbuf_depth =mei_dma_ring_hbuf_depth (dev); wr_idx =READ_ONCE (ctrl->hbuf_wr_idx) & (hbuf_depth -1 ); slots =mei_data2slots (len);
drivers/misc/mei/gsc-me.c +7 -9
@@ -106,11 +106,15 @@ static int mei_gsc_probe(struct auxiliary_device *aux_dev, } } + ret =mei_register (dev, device); +if (ret) + goto deinterrupt; +pm_runtime_get_noresume (device);pm_runtime_set_active (device);pm_runtime_enable (device); -/* Continue to char device setup in spite of firmware handshake failure. +/* Continue in spite of firmware handshake failure. * In order to provide access to the firmware status registers to the user * space via sysfs. */
@@ -120,18 +124,12 @@ static int mei_gsc_probe(struct auxiliary_device *aux_dev,pm_runtime_set_autosuspend_delay (device,MEI_GSC_RPM_TIMEOUT );pm_runtime_use_autosuspend (device); - ret =mei_register (dev, device); -if (ret) - goto register_err; -pm_runtime_put_noidle (device);return 0 ; -register_err: -mei_stop (dev); +deinterrupt:if (!mei_me_hw_use_polling (hw))devm_free_irq (device, hw->irq, dev); - err:dev_err (device,"probe failed: %d\n" , ret);dev_set_drvdata (device,NULL );
@@ -252,7 +250,7 @@ static int __maybe_unused mei_gsc_pm_runtime_resume(struct device *device) irq_ret =mei_me_irq_thread_handler (1 , dev);if (irq_ret !=IRQ_HANDLED ) -dev_err (dev->dev,"thread handler fail %d\n" , irq_ret); +dev_err (&dev->dev,"thread handler fail %d\n" , irq_ret);return 0 ; }
drivers/misc/mei/hbm.c +58 -63
410 lines not on this page · raw message
drivers/misc/mei/hw-me.c +50 -50
372 lines not on this page · raw message
drivers/misc/mei/hw-txe.c +30 -30
228 lines not on this page · raw message
drivers/misc/mei/init.c +23 -24
166 lines not on this page · raw message
drivers/misc/mei/interrupt.c +22 -23
155 lines not on this page · raw message
drivers/misc/mei/main.c +33 -14
113 lines not on this page · raw message
drivers/misc/mei/mei_dev.h +5 -3
@@ -470,7 +470,8 @@ struct mei_dev_timeouts {/** * struct mei_device - MEI private device struct * -* @dev : device on a bus +* @parent : device on a bus +* @dev : device object * @cdev : character device pointer * @minor : minor number allocated for device *
@@ -556,7 +557,8 @@ struct mei_dev_timeouts {* @hw : hw specific data */ struct mei_device { -struct device *dev; +struct device *parent; +struct device dev;struct cdev *cdev;int minor;
@@ -703,7 +705,7 @@ static inline u32 mei_slots2data(int slots)* mei init function prototypes */ void mei_device_init (struct mei_device *dev, -struct device *device, +struct device *parent,bool slow_fw,const struct mei_hw_ops *hw_ops);int mei_reset (struct mei_device *dev);
drivers/misc/mei/pci-me.c +10 -10
@@ -143,7 +143,7 @@ static inline void mei_me_unset_pm_domain(struct mei_device *dev) {}static int mei_me_read_fws (const struct mei_device *dev,int where,u32 *val) { -struct pci_dev *pdev =to_pci_dev (dev->dev); +struct pci_dev *pdev =to_pci_dev (dev->parent);return pci_read_config_dword (pdev, where, val); }
@@ -238,19 +238,19 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto end; } + err =mei_register (dev, &pdev->dev); +if (err) + goto release_irq; +if (mei_start (dev)) {dev_err (&pdev->dev,"init hw failure.\n" ); err = -ENODEV ; - goto release_irq; + goto deregister; }pm_runtime_set_autosuspend_delay (&pdev->dev,MEI_ME_RPM_TIMEOUT );pm_runtime_use_autosuspend (&pdev->dev); - err =mei_register (dev, &pdev->dev); -if (err) - goto stop; -pci_set_drvdata (pdev, dev);/*
@@ -280,8 +280,8 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; -stop: -mei_stop (dev); +deregister: +mei_deregister (dev); release_irq:mei_cancel_work (dev);mei_disable_interrupts (dev);
@@ -475,7 +475,7 @@ static int mei_me_pm_runtime_resume(struct device *device)*/ static inline void mei_me_set_pm_domain (struct mei_device *dev) { -struct pci_dev *pdev =to_pci_dev (dev->dev); +struct pci_dev *pdev =to_pci_dev (dev->parent);if (pdev->dev.bus && pdev->dev.bus->pm) { dev->pg_domain.ops = *pdev->dev.bus->pm;
@@ -496,7 +496,7 @@ static inline void mei_me_set_pm_domain(struct mei_device *dev)static inline void mei_me_unset_pm_domain (struct mei_device *dev) {/* stop using pm callbacks if any */ -dev_pm_domain_set (dev->dev,NULL ); +dev_pm_domain_set (dev->parent,NULL ); }static const struct dev_pm_ops mei_me_pm_ops = {
drivers/misc/mei/pci-txe.c +2 -2
@@ -321,7 +321,7 @@ static int mei_txe_pm_runtime_resume(struct device *device)*/ static inline void mei_txe_set_pm_domain (struct mei_device *dev) { -struct pci_dev *pdev =to_pci_dev (dev->dev); +struct pci_dev *pdev =to_pci_dev (dev->parent);if (pdev->dev.bus && pdev->dev.bus->pm) { dev->pg_domain.ops = *pdev->dev.bus->pm;
@@ -342,7 +342,7 @@ static inline void mei_txe_set_pm_domain(struct mei_device *dev)static inline void mei_txe_unset_pm_domain (struct mei_device *dev) {/* stop using pm callbacks if any */ -dev_pm_domain_set (dev->dev,NULL ); +dev_pm_domain_set (dev->parent,NULL ); }static const struct dev_pm_ops mei_txe_pm_ops = {
drivers/misc/mei/platform-vsc.c +13 -13
@@ -152,7 +152,7 @@ static int mei_vsc_hw_start(struct mei_device *mei_dev)MEI_VSC_POLL_TIMEOUT_US , true, hw, &buf, sizeof(buf));if (ret) { -dev_err (mei_dev->dev,"wait fw ready failed: %d\n" , ret); +dev_err (&mei_dev->dev,"wait fw ready failed: %d\n" , ret);return ret; }
@@ -256,7 +256,7 @@ static int mei_vsc_hw_reset(struct mei_device *mei_dev, bool intr_enable)vsc_tp_reset (hw->tp); -return vsc_tp_init (hw->tp, mei_dev->dev); +return vsc_tp_init (hw->tp, mei_dev->parent); }static const struct mei_hw_ops mei_vsc_hw_ops = {
@@ -322,7 +322,7 @@ static void mei_vsc_event_cb(void *context) mei_dev->hbuf_is_ready =mei_hbuf_is_ready (mei_dev); ret =mei_irq_write_handler (mei_dev, &cmpl_list);if (ret) -dev_err (mei_dev->dev,"dispatch write request failed: %d\n" , ret); +dev_err (&mei_dev->dev,"dispatch write request failed: %d\n" , ret); mei_dev->hbuf_is_ready =mei_hbuf_is_ready (mei_dev);mei_irq_compl_handler (mei_dev, &cmpl_list);
@@ -340,12 +340,12 @@ static int mei_vsc_probe(struct platform_device *pdev)if (!tp)return dev_err_probe (dev, -ENODEV ,"no platform data\n" ); - mei_dev =devm_kzalloc (dev,size_add (sizeof (*mei_dev),sizeof (*hw)), -GFP_KERNEL ); + mei_dev =kzalloc (size_add (sizeof (*mei_dev),sizeof (*hw)),GFP_KERNEL );if (!mei_dev)return -ENOMEM ;mei_device_init (mei_dev, dev, false, &mei_vsc_hw_ops); + mei_dev->fw_f_fw_ver_supported =0 ; mei_dev->kind ="ivsc" ;
@@ -357,22 +357,22 @@ static int mei_vsc_probe(struct platform_device *pdev)vsc_tp_register_event_cb (tp, mei_vsc_event_cb, mei_dev); + ret =mei_register (mei_dev, dev); +if (ret) + goto err_dereg; + ret =mei_start (mei_dev);if (ret) {dev_err_probe (dev, ret,"init hw failed\n" ); goto err_cancel; } - ret =mei_register (mei_dev, dev); -if (ret) - goto err_stop; - -pm_runtime_enable (mei_dev->dev); +pm_runtime_enable (mei_dev->parent);return 0 ; -err_stop: -mei_stop (mei_dev); +err_dereg: +mei_deregister (mei_dev); err_cancel:mei_cancel_work (mei_dev);
@@ -386,7 +386,7 @@ static void mei_vsc_remove(struct platform_device *pdev) {struct mei_device *mei_dev =platform_get_drvdata (pdev); -pm_runtime_disable (mei_dev->dev); +pm_runtime_disable (mei_dev->parent);mei_stop (mei_dev);
Signature · 1 line
2.43.0