Commit dd5700ea authored by Marcin Slusarz's avatar Marcin Slusarz Committed by Ben Skeggs

drm/nouveau: fix nouveau_client allocation failure path

Depending on the point of failure, freed object would be returned
or memory leak would happen.
Signed-off-by: default avatarMarcin Slusarz <marcin.slusarz@gmail.com>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 82c805ab
...@@ -66,10 +66,8 @@ nouveau_client_create_(const char *name, u64 devname, const char *cfg, ...@@ -66,10 +66,8 @@ nouveau_client_create_(const char *name, u64 devname, const char *cfg,
ret = nouveau_handle_create(nv_object(client), ~0, ~0, ret = nouveau_handle_create(nv_object(client), ~0, ~0,
nv_object(client), &client->root); nv_object(client), &client->root);
if (ret) { if (ret)
nouveau_namedb_destroy(&client->base);
return ret; return ret;
}
/* prevent init/fini being called, os in in charge of this */ /* prevent init/fini being called, os in in charge of this */
atomic_set(&nv_object(client)->usecount, 2); atomic_set(&nv_object(client)->usecount, 2);
......
...@@ -36,6 +36,9 @@ nouveau_client(void *obj) ...@@ -36,6 +36,9 @@ nouveau_client(void *obj)
int nouveau_client_create_(const char *name, u64 device, const char *cfg, int nouveau_client_create_(const char *name, u64 device, const char *cfg,
const char *dbg, int, void **); const char *dbg, int, void **);
#define nouveau_client_destroy(p) \
nouveau_namedb_destroy(&(p)->base)
int nouveau_client_init(struct nouveau_client *); int nouveau_client_init(struct nouveau_client *);
int nouveau_client_fini(struct nouveau_client *, bool suspend); int nouveau_client_fini(struct nouveau_client *, bool suspend);
......
...@@ -84,11 +84,16 @@ nouveau_cli_create(struct pci_dev *pdev, const char *name, ...@@ -84,11 +84,16 @@ nouveau_cli_create(struct pci_dev *pdev, const char *name,
struct nouveau_cli *cli; struct nouveau_cli *cli;
int ret; int ret;
*pcli = NULL;
ret = nouveau_client_create_(name, nouveau_name(pdev), nouveau_config, ret = nouveau_client_create_(name, nouveau_name(pdev), nouveau_config,
nouveau_debug, size, pcli); nouveau_debug, size, pcli);
cli = *pcli; cli = *pcli;
if (ret) if (ret) {
if (cli)
nouveau_client_destroy(&cli->base);
*pcli = NULL;
return ret; return ret;
}
mutex_init(&cli->mutex); mutex_init(&cli->mutex);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment