summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-03-08 20:07:45 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2017-03-22 21:37:10 -0400
commit4a94c135f062ab41bc99376aa1a4bd64d33e47d9 (patch)
tree7c2e4033833001b355d9b4c793c137582e52c69b /drivers/gpu/nvgpu/gk20a/channel_gk20a.c
parent14188ba419b980b74d964ee7d2de5fc3dd9f9a90 (diff)
gpu: nvgpu: Use new kmem API functions (channel)
Use the new kmem API functions in the channel and channel related code. Also delete the usage of kasprintf() since that must be paired with a kfree(). Since the kasprintf() doesn't use the nvgpu kmem machinery (and is Linux specific) instead use a small buffer statically allocated on the stack. Bug 1799159 Bug 1823380 Change-Id: Ied0183f57372632264e55608f56539861cc0f24f Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1318312 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/channel_gk20a.c')
-rw-r--r--drivers/gpu/nvgpu/gk20a/channel_gk20a.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
index c09539ff..26fbd66e 100644
--- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
@@ -26,7 +26,6 @@
26#include <linux/file.h> 26#include <linux/file.h>
27#include <linux/anon_inodes.h> 27#include <linux/anon_inodes.h>
28#include <linux/dma-buf.h> 28#include <linux/dma-buf.h>
29#include <linux/vmalloc.h>
30#include <linux/circ_buf.h> 29#include <linux/circ_buf.h>
31 30
32#include <nvgpu/semaphore.h> 31#include <nvgpu/semaphore.h>
@@ -1244,7 +1243,7 @@ int gk20a_channel_release(struct inode *inode, struct file *filp)
1244 1243
1245channel_release: 1244channel_release:
1246 gk20a_put(g); 1245 gk20a_put(g);
1247 kfree(filp->private_data); 1246 nvgpu_kfree(g, filp->private_data);
1248 filp->private_data = NULL; 1247 filp->private_data = NULL;
1249 return 0; 1248 return 0;
1250} 1249}
@@ -1390,7 +1389,7 @@ static int __gk20a_channel_open(struct gk20a *g, struct file *filp, s32 runlist_
1390 1389
1391 trace_gk20a_channel_open(dev_name(g->dev)); 1390 trace_gk20a_channel_open(dev_name(g->dev));
1392 1391
1393 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1392 priv = nvgpu_kzalloc(g, sizeof(*priv));
1394 if (!priv) { 1393 if (!priv) {
1395 err = -ENOMEM; 1394 err = -ENOMEM;
1396 goto free_ref; 1395 goto free_ref;
@@ -1421,7 +1420,7 @@ static int __gk20a_channel_open(struct gk20a *g, struct file *filp, s32 runlist_
1421 return 0; 1420 return 0;
1422 1421
1423fail_busy: 1422fail_busy:
1424 kfree(priv); 1423 nvgpu_kfree(g, priv);
1425free_ref: 1424free_ref:
1426 gk20a_put(g); 1425 gk20a_put(g);
1427 return err; 1426 return err;
@@ -1446,7 +1445,7 @@ int gk20a_channel_open_ioctl(struct gk20a *g,
1446 int err; 1445 int err;
1447 int fd; 1446 int fd;
1448 struct file *file; 1447 struct file *file;
1449 char *name; 1448 char name[64];
1450 s32 runlist_id = args->in.runlist_id; 1449 s32 runlist_id = args->in.runlist_id;
1451 1450
1452 err = get_unused_fd_flags(O_RDWR); 1451 err = get_unused_fd_flags(O_RDWR);
@@ -1454,15 +1453,10 @@ int gk20a_channel_open_ioctl(struct gk20a *g,
1454 return err; 1453 return err;
1455 fd = err; 1454 fd = err;
1456 1455
1457 name = kasprintf(GFP_KERNEL, "nvhost-%s-fd%d", 1456 snprintf(name, sizeof(name), "nvhost-%s-fd%d",
1458 dev_name(g->dev), fd); 1457 dev_name(g->dev), fd);
1459 if (!name) {
1460 err = -ENOMEM;
1461 goto clean_up;
1462 }
1463 1458
1464 file = anon_inode_getfile(name, g->channel.cdev.ops, NULL, O_RDWR); 1459 file = anon_inode_getfile(name, g->channel.cdev.ops, NULL, O_RDWR);
1465 kfree(name);
1466 if (IS_ERR(file)) { 1460 if (IS_ERR(file)) {
1467 err = PTR_ERR(file); 1461 err = PTR_ERR(file);
1468 goto clean_up; 1462 goto clean_up;
@@ -1609,7 +1603,7 @@ static void free_priv_cmdbuf(struct channel_gk20a *c,
1609 if (channel_gk20a_is_prealloc_enabled(c)) 1603 if (channel_gk20a_is_prealloc_enabled(c))
1610 memset(e, 0, sizeof(struct priv_cmd_entry)); 1604 memset(e, 0, sizeof(struct priv_cmd_entry));
1611 else 1605 else
1612 kfree(e); 1606 nvgpu_kfree(c->g, e);
1613} 1607}
1614 1608
1615static int channel_gk20a_alloc_job(struct channel_gk20a *c, 1609static int channel_gk20a_alloc_job(struct channel_gk20a *c,
@@ -1635,8 +1629,8 @@ static int channel_gk20a_alloc_job(struct channel_gk20a *c,
1635 err = -EAGAIN; 1629 err = -EAGAIN;
1636 } 1630 }
1637 } else { 1631 } else {
1638 *job_out = kzalloc(sizeof(struct channel_gk20a_job), 1632 *job_out = nvgpu_kzalloc(c->g,
1639 GFP_KERNEL); 1633 sizeof(struct channel_gk20a_job));
1640 if (!*job_out) 1634 if (!*job_out)
1641 err = -ENOMEM; 1635 err = -ENOMEM;
1642 } 1636 }
@@ -1659,7 +1653,7 @@ static void channel_gk20a_free_job(struct channel_gk20a *c,
1659 job->wait_cmd = wait_cmd; 1653 job->wait_cmd = wait_cmd;
1660 job->incr_cmd = incr_cmd; 1654 job->incr_cmd = incr_cmd;
1661 } else 1655 } else
1662 kfree(job); 1656 nvgpu_kfree(c->g, job);
1663} 1657}
1664 1658
1665void channel_gk20a_joblist_lock(struct channel_gk20a *c) 1659void channel_gk20a_joblist_lock(struct channel_gk20a *c)
@@ -1757,7 +1751,8 @@ static int channel_gk20a_prealloc_resources(struct channel_gk20a *c,
1757 */ 1751 */
1758 size = sizeof(struct channel_gk20a_job); 1752 size = sizeof(struct channel_gk20a_job);
1759 if (num_jobs <= ULONG_MAX / size) 1753 if (num_jobs <= ULONG_MAX / size)
1760 c->joblist.pre_alloc.jobs = vzalloc(num_jobs * size); 1754 c->joblist.pre_alloc.jobs = nvgpu_vzalloc(c->g,
1755 num_jobs * size);
1761 if (!c->joblist.pre_alloc.jobs) { 1756 if (!c->joblist.pre_alloc.jobs) {
1762 err = -ENOMEM; 1757 err = -ENOMEM;
1763 goto clean_up; 1758 goto clean_up;
@@ -1770,7 +1765,7 @@ static int channel_gk20a_prealloc_resources(struct channel_gk20a *c,
1770 */ 1765 */
1771 size = sizeof(struct priv_cmd_entry); 1766 size = sizeof(struct priv_cmd_entry);
1772 if (num_jobs <= ULONG_MAX / (size << 1)) 1767 if (num_jobs <= ULONG_MAX / (size << 1))
1773 entries = vzalloc((num_jobs << 1) * size); 1768 entries = nvgpu_vzalloc(c->g, (num_jobs << 1) * size);
1774 if (!entries) { 1769 if (!entries) {
1775 err = -ENOMEM; 1770 err = -ENOMEM;
1776 goto clean_up_joblist; 1771 goto clean_up_joblist;
@@ -1799,9 +1794,9 @@ static int channel_gk20a_prealloc_resources(struct channel_gk20a *c,
1799 return 0; 1794 return 0;
1800 1795
1801clean_up_priv_cmd: 1796clean_up_priv_cmd:
1802 vfree(entries); 1797 nvgpu_vfree(c->g, entries);
1803clean_up_joblist: 1798clean_up_joblist:
1804 vfree(c->joblist.pre_alloc.jobs); 1799 nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs);
1805clean_up: 1800clean_up:
1806 memset(&c->joblist.pre_alloc, 0, sizeof(c->joblist.pre_alloc)); 1801 memset(&c->joblist.pre_alloc, 0, sizeof(c->joblist.pre_alloc));
1807 return err; 1802 return err;
@@ -1809,8 +1804,8 @@ clean_up:
1809 1804
1810static void channel_gk20a_free_prealloc_resources(struct channel_gk20a *c) 1805static void channel_gk20a_free_prealloc_resources(struct channel_gk20a *c)
1811{ 1806{
1812 vfree(c->joblist.pre_alloc.jobs[0].wait_cmd); 1807 nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs[0].wait_cmd);
1813 vfree(c->joblist.pre_alloc.jobs); 1808 nvgpu_vfree(c->g, c->joblist.pre_alloc.jobs);
1814 gk20a_free_fence_pool(c); 1809 gk20a_free_fence_pool(c);
1815 1810
1816 /* 1811 /*
@@ -2910,8 +2905,8 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c,
2910 } 2905 }
2911 2906
2912 if (!pre_alloc_enabled) 2907 if (!pre_alloc_enabled)
2913 job->wait_cmd = kzalloc(sizeof(struct priv_cmd_entry), 2908 job->wait_cmd = nvgpu_kzalloc(g,
2914 GFP_KERNEL); 2909 sizeof(struct priv_cmd_entry));
2915 2910
2916 if (!job->wait_cmd) { 2911 if (!job->wait_cmd) {
2917 err = -ENOMEM; 2912 err = -ENOMEM;
@@ -2951,8 +2946,7 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c,
2951 goto clean_up_wait_cmd; 2946 goto clean_up_wait_cmd;
2952 } 2947 }
2953 if (!pre_alloc_enabled) 2948 if (!pre_alloc_enabled)
2954 job->incr_cmd = kzalloc(sizeof(struct priv_cmd_entry), 2949 job->incr_cmd = nvgpu_kzalloc(g, sizeof(struct priv_cmd_entry));
2955 GFP_KERNEL);
2956 2950
2957 if (!job->incr_cmd) { 2951 if (!job->incr_cmd) {
2958 err = -ENOMEM; 2952 err = -ENOMEM;
@@ -3520,7 +3514,7 @@ static int gk20a_event_id_release(struct inode *inode, struct file *filp)
3520 3514
3521 nvgpu_mutex_destroy(&event_id_data->lock); 3515 nvgpu_mutex_destroy(&event_id_data->lock);
3522 gk20a_put(g); 3516 gk20a_put(g);
3523 kfree(event_id_data); 3517 nvgpu_kfree(g, event_id_data);
3524 filp->private_data = NULL; 3518 filp->private_data = NULL;
3525 3519
3526 return 0; 3520 return 0;
@@ -3588,7 +3582,7 @@ static int gk20a_channel_event_id_enable(struct channel_gk20a *ch,
3588 int err = 0; 3582 int err = 0;
3589 int local_fd; 3583 int local_fd;
3590 struct file *file; 3584 struct file *file;
3591 char *name; 3585 char name[64];
3592 struct gk20a_event_id_data *event_id_data; 3586 struct gk20a_event_id_data *event_id_data;
3593 3587
3594 g = gk20a_get(ch->g); 3588 g = gk20a_get(ch->g);
@@ -3608,18 +3602,16 @@ static int gk20a_channel_event_id_enable(struct channel_gk20a *ch,
3608 goto free_ref; 3602 goto free_ref;
3609 local_fd = err; 3603 local_fd = err;
3610 3604
3611 name = kasprintf(GFP_KERNEL, "nvgpu-event%d-fd%d", 3605 snprintf(name, sizeof(name), "nvgpu-event%d-fd%d",
3612 event_id, local_fd); 3606 event_id, local_fd);
3613
3614 file = anon_inode_getfile(name, &gk20a_event_id_ops, 3607 file = anon_inode_getfile(name, &gk20a_event_id_ops,
3615 NULL, O_RDWR); 3608 NULL, O_RDWR);
3616 kfree(name);
3617 if (IS_ERR(file)) { 3609 if (IS_ERR(file)) {
3618 err = PTR_ERR(file); 3610 err = PTR_ERR(file);
3619 goto clean_up; 3611 goto clean_up;
3620 } 3612 }
3621 3613
3622 event_id_data = kzalloc(sizeof(*event_id_data), GFP_KERNEL); 3614 event_id_data = nvgpu_kzalloc(ch->g, sizeof(*event_id_data));
3623 if (!event_id_data) { 3615 if (!event_id_data) {
3624 err = -ENOMEM; 3616 err = -ENOMEM;
3625 goto clean_up_file; 3617 goto clean_up_file;