Skip to content

Commit

Permalink
riscv: amp: fix rpmsg driver override kfree static memory
Browse files Browse the repository at this point in the history
User can not modify rpmsg sysfs driver_override file,
because rpdev->driver_override is allocate in the static memory.
So dynamic allocate memory for rpdev->driver_override.

Signed-off-by: Charles Ci-Jyun Wu <dminus@andestech.com>
Reviewed-by: Dylan Jhong <dylan@andestech.com>
Reviewed-by: Randolph <randolph@andestech.com>
  • Loading branch information
Charles Ci-Jyun Wu authored and Leo Yu-Chi Liang committed Nov 1, 2022
1 parent 145a47e commit 7e67617
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions drivers/rpmsg/rpmsg_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,19 @@ int rpmsg_release_channel(struct rpmsg_device *rpdev,
*/
static inline int rpmsg_chrdev_register_device(struct rpmsg_device *rpdev)
{
strcpy(rpdev->id.name, "rpmsg_chrdev");
rpdev->driver_override = "rpmsg_chrdev";
char *driver = "rpmsg_chrdev", *driver_override;

strcpy(rpdev->id.name, driver);

driver_override = kstrndup(driver, strlen(driver), GFP_KERNEL);
if (!driver_override)
return -ENOMEM;

driver_override[strcspn(driver_override, "\n")] = '\0';

device_lock(&rpdev->dev);
rpdev->driver_override = driver_override;
device_unlock(&rpdev->dev);

return rpmsg_register_device(rpdev);
}
Expand Down
15 changes: 13 additions & 2 deletions drivers/rpmsg/rpmsg_ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
*/
int rpmsg_ns_register_device(struct rpmsg_device *rpdev)
{
strcpy(rpdev->id.name, "rpmsg_ns");
rpdev->driver_override = "rpmsg_ns";
char *driver = "rpmsg_ns", *driver_override;
strcpy(rpdev->id.name, driver);

driver_override = kstrndup(driver, strlen(driver), GFP_KERNEL);
if (!driver_override)
return -ENOMEM;

driver_override[strcspn(driver_override, "\n")] = '\0';

device_lock(&rpdev->dev);
rpdev->driver_override = driver_override;
device_unlock(&rpdev->dev);

rpdev->src = RPMSG_NS_ADDR;
rpdev->dst = RPMSG_NS_ADDR;

Expand Down

0 comments on commit 7e67617

Please sign in to comment.