From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E97ACC3815B for ; Mon, 20 Apr 2020 09:24:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C94B020CC7 for ; Mon, 20 Apr 2020 09:24:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="ygm2kM8Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726228AbgDTJY2 (ORCPT ); Mon, 20 Apr 2020 05:24:28 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:35115 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbgDTJY1 (ORCPT ); Mon, 20 Apr 2020 05:24:27 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03K9Mm8r004307; Mon, 20 Apr 2020 11:24:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=STMicroelectronics; bh=s8K4dHG+7OIzZ7R9bQBGG4blMOhessXM8j6Dk6jooSY=; b=ygm2kM8YY9J+l7QLFg5ttmVA3ljCeD57Dza2EZukwBnG3fad2rlhUw1zqXcWOL5E7r9W vCHrnYjYfEJGbN5wTucgW6FCQurRm5zeuHaDQVg8o6RCNipCNe/l3o2SoDxCBDTRAD1l 2viqm6axHYztGeKH7Ahdr+lg4NeWDU/aSgEJmStSVtvYP9mtJCeUiOjuQXfCjxkRZCBL 2jSHr8mfEqp0UXeHD/0jyfWhKyGyxLB9i2olbZO5TcPNeAPFwJozSK7OczlGUGQibkeQ qde5R7pnvtVVFt/eXnVUJ/L9vvDA+kP19UMA0Pl9Zz7Q1gejlcIZGpwh3A2v2+txGCxd uA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 30fqaw1ctx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Apr 2020 11:24:21 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0613410002A; Mon, 20 Apr 2020 11:24:21 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id E6A882BEC7A; Mon, 20 Apr 2020 11:24:20 +0200 (CEST) Received: from lmecxl0889.tpe.st.com (10.75.127.48) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 20 Apr 2020 11:24:19 +0200 Subject: Re: [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() To: Mathieu Poirier , , CC: , , , , References: <20200415204858.2448-1-mathieu.poirier@linaro.org> <20200415204858.2448-3-mathieu.poirier@linaro.org> From: Arnaud POULIQUEN Message-ID: Date: Mon, 20 Apr 2020 11:24:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200415204858.2448-3-mathieu.poirier@linaro.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-20_03:2020-04-17,2020-04-20 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu, On 4/15/20 10:48 PM, Mathieu Poirier wrote: > Make the firmware name allocation a function on its own in an > effort to cleanup function rproc_alloc(). > > Signed-off-by: Mathieu Poirier > --- > drivers/remoteproc/remoteproc_core.c | 66 ++++++++++++++++------------ > 1 file changed, 39 insertions(+), 27 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index 80056513ae71..4dee63f319ba 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = { > .release = rproc_type_release, > }; > > +static int rproc_alloc_firmware(struct rproc *rproc, > + const char *name, const char *firmware) nitpicking: here you do not allocate memory for the firmware but for its name The name of the function seems to me quite confusing... Else LGTM for the series Thanks, Arnaud > +{ > + char *p, *template = "rproc-%s-fw"; > + int name_len; > + > + if (!firmware) { > + /* > + * If the caller didn't pass in a firmware name then > + * construct a default name. > + */ > + name_len = strlen(name) + strlen(template) - 2 + 1; > + p = kmalloc(name_len, GFP_KERNEL); > + if (!p) > + return -ENOMEM; > + snprintf(p, name_len, template, name); > + } else { > + p = kstrdup(firmware, GFP_KERNEL); > + if (!p) > + return -ENOMEM; > + } > + > + rproc->firmware = p; > + > + return 0; > +} > + > /** > * rproc_alloc() - allocate a remote processor handle > * @dev: the underlying device > @@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, > const char *firmware, int len) > { > struct rproc *rproc; > - char *p, *template = "rproc-%s-fw"; > - int name_len; > > if (!dev || !name || !ops) > return NULL; > > - if (!firmware) { > - /* > - * If the caller didn't pass in a firmware name then > - * construct a default name. > - */ > - name_len = strlen(name) + strlen(template) - 2 + 1; > - p = kmalloc(name_len, GFP_KERNEL); > - if (!p) > - return NULL; > - snprintf(p, name_len, template, name); > - } else { > - p = kstrdup(firmware, GFP_KERNEL); > - if (!p) > - return NULL; > - } > - > rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); > - if (!rproc) { > - kfree(p); > + if (!rproc) > return NULL; > - } > + > + if (rproc_alloc_firmware(rproc, name, firmware)) > + goto free_rproc; > > rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); > - if (!rproc->ops) { > - kfree(p); > - kfree(rproc); > - return NULL; > - } > + if (!rproc->ops) > + goto free_firmware; > > - rproc->firmware = p; > rproc->name = name; > rproc->priv = &rproc[1]; > rproc->auto_boot = true; > @@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, > rproc->state = RPROC_OFFLINE; > > return rproc; > + > +free_firmware: > + kfree(rproc->firmware); > +free_rproc: > + kfree(rproc); > + return NULL; > } > EXPORT_SYMBOL(rproc_alloc); > >