From: Fabiano Rosas Date: Mon, 19 Jul 2021 19:09:44 +0000 Subject: Re: [PATCH v5 1/1] powerpc/pseries: Interface to represent PAPR firmware attributes Message-Id: <87fswa2k93.fsf@linux.ibm.com> List-Id: References: <20210719093250.41405-1-psampat@linux.ibm.com> <20210719093250.41405-2-psampat@linux.ibm.com> In-Reply-To: <20210719093250.41405-2-psampat@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: "Pratik R. Sampat" , 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, psampat@linux.ibm.com, pratik.r.sampat@gmail.com "Pratik R. Sampat" 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. > + 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);