kvm-ppc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pratik Sampat <psampat@linux.ibm.com>
To: Fabiano Rosas <farosas@linux.ibm.com>,
	mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org,
	linuxppc-dev@lists.ozlabs.org, kvm-ppc@vger.kernel.org,
	linux-kernel@vger.kernel.org, pratik.r.sampat@gmail.com
Subject: Re: [PATCH v5 1/1] powerpc/pseries: Interface to represent PAPR firmware attributes
Date: Tue, 20 Jul 2021 05:16:22 +0000	[thread overview]
Message-ID: <de3c5540-2a07-8373-57a2-a89e3d304413@linux.ibm.com> (raw)
In-Reply-To: <87fswa2k93.fsf@linux.ibm.com>



On 20/07/21 12:39 am, Fabiano Rosas wrote:
> "Pratik R. Sampat" <psampat@linux.ibm.com> writes:
>
>> +	pgs = kcalloc(num_attrs, sizeof(*pgs), GFP_KERNEL);
>> +	if (!pgs)
>> +		goto out;
>> +
>> +	papr_kobj = kobject_create_and_add("papr", firmware_kobj);
>> +	if (!papr_kobj) {
>> +		pr_warn("kobject_create_and_add papr failed\n");
>> +		goto out_pgs;
>> +	}
>> +
>> +	esi_kobj = kobject_create_and_add("energy_scale_info", papr_kobj);
>> +	if (!esi_kobj) {
>> +		pr_warn("kobject_create_and_add energy_scale_info failed\n");
>> +		goto out_kobj;
>> +	}
>> +
>> +	for (idx = 0; idx < num_attrs; idx++) {
>> +		bool show_val_desc = true;
>> +
>> +		pgs[idx].pg.attrs = kcalloc(MAX_ATTRS + 1,
>> +					    sizeof(*pgs[idx].pg.attrs),
>> +					    GFP_KERNEL);
>> +		if (!pgs[idx].pg.attrs) {
>> +			for (i = idx - 1; i >= 0; i--)
>> +				kfree(pgs[i].pg.attrs);
> What about the pg.name from the previous iterations?
>
>> +			goto out_ekobj;
>> +		}
>> +
>> +		pgs[idx].pg.name = kasprintf(GFP_KERNEL, "%lld",
>> +					     be64_to_cpu(esi_attrs[idx].id));
>> +		if (pgs[idx].pg.name = NULL) {
>> +			for (i = idx; i >= 0; i--)
>> +				kfree(pgs[i].pg.attrs);
> Here too.
>
> You could just 'goto out_pgattrs' in both cases.

Yeah, you're right. I may have over-complicated the free, in case of
failure in both the cases above I could just free from "out_pgattrs"
with no issues

>> +			goto out_ekobj;
>> +		}
>> +		/* Do not add the value description if it does not exist */
>> +		if (strnlen(esi_attrs[idx].value_desc,
>> +			    sizeof(esi_attrs[idx].value_desc)) = 0)
>> +			show_val_desc = false;
>> +
>> +		if (add_attr_group(be64_to_cpu(esi_attrs[idx].id), &pgs[idx],
>> +				   show_val_desc)) {
>> +			pr_warn("Failed to create papr attribute group %s\n",
>> +				pgs[idx].pg.name);
>> +			goto out_pgattrs;
>> +		}
>> +	}
>> +
>> +	kfree(esi_buf);
>> +	return 0;
>> +
>> +out_pgattrs:
>> +	for (i = 0; i < num_attrs ; i++) {
>> +		kfree(pgs[i].pg.attrs);
>> +		kfree(pgs[i].pg.name);
>> +	}
>> +out_ekobj:
>> +	kobject_put(esi_kobj);
>> +out_kobj:
>> +	kobject_put(papr_kobj);
>> +out_pgs:
>> +	kfree(pgs);
>> +out:
>> +	kfree(esi_buf);
>> +
>> +	return -ENOMEM;
>> +}
>> +
>> +machine_device_initcall(pseries, papr_init);

      reply	other threads:[~2021-07-20  5:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19  9:44 [PATCH v5 0/1] Interface to represent PAPR firmware attributes Pratik R. Sampat
2021-07-19  9:44 ` [PATCH v5 1/1] powerpc/pseries: " Pratik R. Sampat
2021-07-19 19:09   ` Fabiano Rosas
2021-07-20  5:16     ` Pratik Sampat [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=de3c5540-2a07-8373-57a2-a89e3d304413@linux.ibm.com \
    --to=psampat@linux.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=farosas@linux.ibm.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=pratik.r.sampat@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).