mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-01 22:54:01 +00:00
selinux: factor out loop body from filename_trans_read()
It simplifies cleanup in the error path. This will be extra useful in later patch. Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Paul Moore <paul@paul-moore.com>
This commit is contained in:
parent
4ca54d3d30
commit
253050f57c
1 changed files with 66 additions and 62 deletions
|
@ -1880,31 +1880,18 @@ static int range_read(struct policydb *p, void *fp)
|
|||
return rc;
|
||||
}
|
||||
|
||||
static int filename_trans_read(struct policydb *p, void *fp)
|
||||
static int filename_trans_read_one(struct policydb *p, void *fp)
|
||||
{
|
||||
struct filename_trans *ft;
|
||||
struct filename_trans_datum *otype;
|
||||
char *name;
|
||||
u32 nel, len;
|
||||
struct filename_trans_datum *otype = NULL;
|
||||
char *name = NULL;
|
||||
u32 len;
|
||||
__le32 buf[4];
|
||||
int rc, i;
|
||||
int rc;
|
||||
|
||||
if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
|
||||
return 0;
|
||||
|
||||
rc = next_entry(buf, fp, sizeof(u32));
|
||||
if (rc)
|
||||
return rc;
|
||||
nel = le32_to_cpu(buf[0]);
|
||||
|
||||
for (i = 0; i < nel; i++) {
|
||||
otype = NULL;
|
||||
name = NULL;
|
||||
|
||||
rc = -ENOMEM;
|
||||
ft = kzalloc(sizeof(*ft), GFP_KERNEL);
|
||||
if (!ft)
|
||||
goto out;
|
||||
return -ENOMEM;
|
||||
|
||||
rc = -ENOMEM;
|
||||
otype = kmalloc(sizeof(*otype), GFP_KERNEL);
|
||||
|
@ -1944,24 +1931,41 @@ static int filename_trans_read(struct policydb *p, void *fp)
|
|||
* Do not return -EEXIST to the caller, or the system
|
||||
* will not boot.
|
||||
*/
|
||||
if (rc != -EEXIST)
|
||||
if (rc == -EEXIST)
|
||||
rc = 0;
|
||||
goto out;
|
||||
/* But free memory to avoid memory leak. */
|
||||
kfree(ft);
|
||||
kfree(name);
|
||||
kfree(otype);
|
||||
}
|
||||
}
|
||||
hash_eval(p->filename_trans, "filenametr");
|
||||
return 0;
|
||||
out:
|
||||
kfree(ft);
|
||||
kfree(name);
|
||||
kfree(otype);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int filename_trans_read(struct policydb *p, void *fp)
|
||||
{
|
||||
u32 nel;
|
||||
__le32 buf[1];
|
||||
int rc, i;
|
||||
|
||||
if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
|
||||
return 0;
|
||||
|
||||
rc = next_entry(buf, fp, sizeof(u32));
|
||||
if (rc)
|
||||
return rc;
|
||||
nel = le32_to_cpu(buf[0]);
|
||||
|
||||
for (i = 0; i < nel; i++) {
|
||||
rc = filename_trans_read_one(p, fp);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
hash_eval(p->filename_trans, "filenametr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int genfs_read(struct policydb *p, void *fp)
|
||||
{
|
||||
int i, j, rc;
|
||||
|
|
Loading…
Reference in a new issue