From patchwork Wed Apr 15 20:48:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11492007 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 501C213B2 for ; Wed, 15 Apr 2020 20:49:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3808920787 for ; Wed, 15 Apr 2020 20:49:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="H8SbRls/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438349AbgDOUtD (ORCPT ); Wed, 15 Apr 2020 16:49:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438343AbgDOUtD (ORCPT ); Wed, 15 Apr 2020 16:49:03 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E13D0C061A0F for ; Wed, 15 Apr 2020 13:49:01 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id cl8so358053pjb.3 for ; Wed, 15 Apr 2020 13:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zAUMwcz72DsKEuRs9bmL8Y0NybdOC1J0IH9IhQjMIJE=; b=H8SbRls/eH+WXZTeEn017Mn94wfGTRZ63+KJ84mB/Sx9X6+gmd7jHt2e1KOHDb+H2v muxqS+OeqsD++0tyg/qpzsRMD7e15CqwIlmrtfnyEg2Uqjhp7TQFCOEJGUDlW9sXhqBV gOq55woguGrjyT9mE6P2euZNMBXyiFBzmJcVSr69aFnCS4I46kH7AvI0hihXdtxL++ar 2JhP3aizQ3oNVB+W9AyvVThNXjl4Img4lT4YHPzqs+HsFy7bMFzOrLeYeXEbtVPsAfIg pWe8O9SV1uNnCs1sI1WKgkjYTvj09xmP6m2ahlPi5k/der8QpCVVpwEerfetP7BlpQxQ JkNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zAUMwcz72DsKEuRs9bmL8Y0NybdOC1J0IH9IhQjMIJE=; b=bRkPV/ww7+WEDf1ue2kNWvoHIY/8z6zf7aPk/buHRnhomdU5w7+fXYe7UKIoJUUtoC D1m44fGGptOKwTJiMa1glW8ElsfkuWkmDICY7DefYUp+o0IEPqWjLdHirBzhxfTB85bH M2w7dUe9sKEfL+ZRwoZTG8H3W53BL33Fz23TXOHYtJgI26x3NOti3dVrrQdzNFXeJgrm fJTxGLng5OWGXLHWILQh0O6La+q+6JtMHWGpiaAgE2SE6aWN9QItbZN53rGw9U+Zd9ck f1cZH12YE6l48cJRZ3KpfFGaYw6R8FHZZbbxGYzfoamCdHEOJ4Uj+ZvX/rGzHaTRWedp F7Ig== X-Gm-Message-State: AGi0PuaO63TF30hhPEAnYli4YEwUGzhxqUSVCCdsI7BRwG99xTcHe1E5 F5A3Y4IUmbfR2RF1o4ZsPyAYyA== X-Google-Smtp-Source: APiQypL0QuvSDhEfisupDM9x2X5iJzOnRw1su0Bt0l9c1CMw1ilBYIgBy+dToz3M/f1hgmjWwsJPhg== X-Received: by 2002:a17:90a:2602:: with SMTP id l2mr1255975pje.110.1586983741413; Wed, 15 Apr 2020 13:49:01 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i13sm14461861pfa.113.2020.04.15.13.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:49:01 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Date: Wed, 15 Apr 2020 14:48:52 -0600 Message-Id: <20200415204858.2448-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org> References: <20200415204858.2448-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Alex Elder If ida_simple_get() returns an error when called in rproc_alloc(), put_device() is called to clean things up. By this time the rproc device type has been assigned, with rproc_type_release() as the release function. The first thing rproc_type_release() does is call: idr_destroy(&rproc->notifyids); But at the time the ida_simple_get() call is made, the notifyids field in the remoteproc structure has not been initialized. I'm not actually sure this case causes an observable problem, but it's incorrect. Fix this by initializing the notifyids field before calling ida_simple_get() in rproc_alloc(). Fixes: b5ab5e24e960 ("remoteproc: maintain a generic child device for each rproc") Signed-off-by: Alex Elder Reviewed-by: Mathieu Poirier Reviewed-by: Suman Anna Reviewed-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e12a54e67588..80056513ae71 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2053,6 +2053,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.type = &rproc_type; rproc->dev.class = &rproc_class; rproc->dev.driver_data = rproc; + idr_init(&rproc->notifyids); /* Assign a unique device index and name */ rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL); @@ -2078,8 +2079,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, mutex_init(&rproc->lock); - idr_init(&rproc->notifyids); - INIT_LIST_HEAD(&rproc->carveouts); INIT_LIST_HEAD(&rproc->mappings); INIT_LIST_HEAD(&rproc->traces); From patchwork Wed Apr 15 20:48:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11492009 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05BDC13B2 for ; Wed, 15 Apr 2020 20:49:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E154E20787 for ; Wed, 15 Apr 2020 20:49:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="egNlW/CS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438664AbgDOUtJ (ORCPT ); Wed, 15 Apr 2020 16:49:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438385AbgDOUtE (ORCPT ); Wed, 15 Apr 2020 16:49:04 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C50C061A0F for ; Wed, 15 Apr 2020 13:49:04 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id c138so582851pfc.0 for ; Wed, 15 Apr 2020 13:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I1hbSYFCQB3yszokgcBiVGsdFzFeGt348+BuoHZMJzg=; b=egNlW/CSCwQuT6WGzglAGTyPjuWi+aGrzOCTdAGwOaEZ7Kgd4B9RHAHH55pOxZzhmU 392kfFr/2vEyV/vcSXdhaRtDqsBzgkk9bN6rOGcWYH1muIyaNkpbGbllThNX7j60A0Vh q4anYq+OzpZrkotySrS6xCtJElR2oV1SpdbngP+leW4q05vQnieuIZuU727i3Zyi2ymc MKQ0947uj0Vey76Ffkj4cYYDMALiAYiHasNiLP8liGtVREahPINgxg8IZIFPQddBO2u9 4BqXf3mIatbMDNLPQsb1flw4HNfji5X6Rc5S+bxDskvpggXJnMecuW5CEVdenaNw75DG MN4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I1hbSYFCQB3yszokgcBiVGsdFzFeGt348+BuoHZMJzg=; b=PrLAbLUR8sIWvi8dqxe5ELPYQh87ZvkmzdBEda0muEEHiww6xnMlB4o0cO3hDDJCes Q58sUkSnA09pP9bhj0ZRbewI2t4Oj+FqZKyv5TwdP6UVnfTKsZt3HFMv875QLbfbVGhF 9d/oOWecP8OHP2TjoJvHAT9/Pvqptr/6Ugz+ARgAs7bi8rEp+HNS7g/UXL15bL95SiDS u074I6CptkoDW546jTJSj/aUjKNRV1skjt+B7L2RjWXUVtgs/XGbdObSP2F5CCZ5XBT8 KxoW5m5lzDvzaksOlLm2IJycJPWy81ihgsvYm+p3q/UOo9qOTdh210k6fJoDAZc4ocRC 72qA== X-Gm-Message-State: AGi0PuZTfMl1dn2IJ13FXtOvEHAXOcZaPuykLXBlr+00ctaA1hWUVK/v spIWwY4EvFdLF1kzIrtZaFQtjA== X-Google-Smtp-Source: APiQypJLUVSXF1Os2JTEHHQ8RcYmeMke3mHN+xDj0GD7Bj66NnNDTeCvgwM5GZlNCsN+NS6a6SupSw== X-Received: by 2002:a63:4047:: with SMTP id n68mr27922364pga.321.1586983744336; Wed, 15 Apr 2020 13:49:04 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i13sm14461861pfa.113.2020.04.15.13.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:49:03 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Date: Wed, 15 Apr 2020 14:48:53 -0600 Message-Id: <20200415204858.2448-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org> References: <20200415204858.2448-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Make the firmware name allocation a function on its own in an effort to cleanup function rproc_alloc(). Signed-off-by: Mathieu Poirier Reviewed-by: Alex Elder Reviewed-by: Bjorn Andersson --- 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) +{ + 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); From patchwork Wed Apr 15 20:48:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11492015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44FF9174A for ; Wed, 15 Apr 2020 20:49:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CD1D2076D for ; Wed, 15 Apr 2020 20:49:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pmJsR3vM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442111AbgDOUtK (ORCPT ); Wed, 15 Apr 2020 16:49:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438465AbgDOUtH (ORCPT ); Wed, 15 Apr 2020 16:49:07 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3081C061A10 for ; Wed, 15 Apr 2020 13:49:05 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id 2so496969pgp.11 for ; Wed, 15 Apr 2020 13:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X7xQkJUM4QmV6qWTvIaQsCBAO/ir+/c43EdRMlg0Sws=; b=pmJsR3vMADCiEuC3ZKRoEyvjBq1QZzx97rLn6fPaWryt3MHuayJKUFwHlbhn+r8AOD asA55ORUfRTr3uD7Q8z5p/QyDbS08f1zy+UqpNFmm0Z3Z2mTsv4lxEG9RcsMpX3HwB+W yGRd3o+f6FGE+AfWv93DKCskICeFWSVVkACz3I6GXLhAuWf7SA6qS+F3kBGN0iZUl6fT K3nvktHz9RuwTFri9hLNzEvNvsKE44ncHhAOSUuUI/OYE2a53l+EK4nYw5oAspI/6Jri VNQJHC/lEOsTzMPMsNv9CdwmyoHA4fVuurHkJ+CIrwKnGKenxFE0KxZu+PeQbcOJMxuX tPJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X7xQkJUM4QmV6qWTvIaQsCBAO/ir+/c43EdRMlg0Sws=; b=RJgvNMZTIcRUR1f0YFhSnlrT+3gtbl/EOL4658+biSk0NxpW3Gglk0OePsmFqo7MKR /gDjx9Mv5QkzXKaC7+FQ0AnZVHKjyYVQhI5XybSrnqe/V/CjtFdIgyWerL0dlAghzwKS ByjEEphc/GrjuaUSJ1YcVGOcuIK3M3m9Ik4P0SKK1/EAQxugqrhSvAGFr0zTC8x3xjDE lJs5KHhxzZfuEHBF361/Wk8Dsc6ROW1nh3+B4AZMpORWVg9mSqvDxS1NKOsQtNhseUNV y8tEBrD0VQ9rUl35I3JO2N5G3/oU3TZeUZDs47ZsaKmiGJUaXBSSKyynF+m4G9uUyTSy kqIg== X-Gm-Message-State: AGi0PuaMp3KHs2TJzUEM8kv2cWs72coPJwYDVl2WbmUql7hExwD7ivpm IIuF8lCa1UMMBOqrpfhzYNy4sA== X-Google-Smtp-Source: APiQypIxyHNKa0iKE7i1LVCf7LxJgykFFNIGEKKj5IapE5xxqMj1NRd3bFf0osSuuOi8WmOUMH0hcw== X-Received: by 2002:a63:2686:: with SMTP id m128mr16210074pgm.283.1586983745414; Wed, 15 Apr 2020 13:49:05 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i13sm14461861pfa.113.2020.04.15.13.49.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:49:05 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] remoteproc: Simplify default name allocation Date: Wed, 15 Apr 2020 14:48:54 -0600 Message-Id: <20200415204858.2448-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org> References: <20200415204858.2448-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org In an effort to cleanup firmware name allocation, replace the cumbersome mechanic used to allocate a default firmware name with function kasprintf(). Suggested-by: Bjorn Andersson Signed-off-by: Mathieu Poirier Reviewed-by: Alex Elder Reviewed-by: Bjorn Andersson --- drivers/remoteproc/remoteproc_core.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 4dee63f319ba..9899467fa1cf 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1982,24 +1982,19 @@ static const struct device_type rproc_type = { static int rproc_alloc_firmware(struct rproc *rproc, const char *name, const char *firmware) { - char *p, *template = "rproc-%s-fw"; - int name_len; + char *p; - if (!firmware) { + 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 = kasprintf(GFP_KERNEL, "rproc-%s-fw", name); + else p = kstrdup(firmware, GFP_KERNEL); - if (!p) - return -ENOMEM; - } + + if (!p) + return -ENOMEM; rproc->firmware = p; From patchwork Wed Apr 15 20:48:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11492017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F3CA13B2 for ; Wed, 15 Apr 2020 20:49:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E21F7206E9 for ; Wed, 15 Apr 2020 20:49:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PzYRWN/b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438385AbgDOUt0 (ORCPT ); Wed, 15 Apr 2020 16:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438617AbgDOUtI (ORCPT ); Wed, 15 Apr 2020 16:49:08 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C515C0610D5 for ; Wed, 15 Apr 2020 13:49:07 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id n16so507005pgb.7 for ; Wed, 15 Apr 2020 13:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M/7ZIhFX8/Fc/kbce4rxbSpECgFr3U/vKIkPqW4pN78=; b=PzYRWN/byflKqd6OsSapeqhz+jz3Mp2vQ5jbUXnfg6/ypN1MtKOn8kz4uKJUQnjzQG zL9RpPo175xED/M6X4ecXyXp9wovIFPGNRW+vCKEH+eTtbJbilLTRK/cmQUzEEYB/6VI IHAbUU2LU3KezQlCkAVUnVFv0miMuzp9V75us5/UFy0YG4Kg+vntVMcf5wJHLLue3cqe KXkHKwfe1+jIFj0/RvkoeUrxClhYzokqu4xvkkAIvlvoPmRgj9Ehc1beneiJ5mWPhGQV bZv86VCUMr1Ead/nuxSjFRA5+2wzV1gwpSY9RILXSi9gO8bNm2hbTRSUH6aHsbFQLa7L sxkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M/7ZIhFX8/Fc/kbce4rxbSpECgFr3U/vKIkPqW4pN78=; b=tGBSLABxH9JD5j3/wJ+aU7QnG24AfGlbQ0snz2XRjY76N9RG2gcI0+CGs52wA3NEXs Mj97zfc/E0kEcviiiiN/E+gqqBz01hXGzdXWARVfs3/+hVixXo4NUr1r0ZZAADfgUWsm AkcbepwdPfFgfQyhkU4bX4XauqqUfWLgtYWx0AydqOrnywewA3IZuE7IfRz5rY741/jI G3GFqfc0IiNJWQWmIsOT2UduqO1POIRlUaIylV6UDnW3qU+cmxwGReRSCI9dRGiy03RC gtKg5a7IXWlvxoGbqHi5U/OsDlp8Ap8vsbYoDr/6m4qplB6HBip9yHA5NWxYNpqXQ5Qh UE0A== X-Gm-Message-State: AGi0PuaO8YIaxmA+UtRFaaccstGgLOf1126LcujfmdKmmwY48XGMJg95 Fsoi2vItYx2zhPGlbuh7qNbFiQ== X-Google-Smtp-Source: APiQypKTLEovDZzfR01SF/kDnhw2CXF7O5puu/Gs/lR7mn9HqDXfXHpcuVfHesxn93ziRZJE2KXJbA== X-Received: by 2002:a62:16d2:: with SMTP id 201mr27883268pfw.295.1586983747037; Wed, 15 Apr 2020 13:49:07 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i13sm14461861pfa.113.2020.04.15.13.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:49:06 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup() Date: Wed, 15 Apr 2020 14:48:55 -0600 Message-Id: <20200415204858.2448-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org> References: <20200415204858.2448-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org For cases where @firmware is declared "const char *", use function kstrdup_const() to avoid needlessly creating another copy on the heap. Suggested-by: Bjorn Andersson Signed-off-by: Mathieu Poirier Reviewed-by: Alex Elder --- drivers/remoteproc/remoteproc_core.c | 4 ++-- include/linux/remoteproc.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 9899467fa1cf..ebaff496ef81 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1982,7 +1982,7 @@ static const struct device_type rproc_type = { static int rproc_alloc_firmware(struct rproc *rproc, const char *name, const char *firmware) { - char *p; + const char *p; if (!firmware) /* @@ -1991,7 +1991,7 @@ static int rproc_alloc_firmware(struct rproc *rproc, */ p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name); else - p = kstrdup(firmware, GFP_KERNEL); + p = kstrdup_const(firmware, GFP_KERNEL); if (!p) return -ENOMEM; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 9c07d7958c53..38607107b7cb 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -489,7 +489,7 @@ struct rproc { struct list_head node; struct iommu_domain *domain; const char *name; - char *firmware; + const char *firmware; void *priv; struct rproc_ops *ops; struct device dev; From patchwork Wed Apr 15 20:48:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11492011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4425B13B2 for ; Wed, 15 Apr 2020 20:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AF4C20787 for ; Wed, 15 Apr 2020 20:49:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SwCYJ9CQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438465AbgDOUtM (ORCPT ); Wed, 15 Apr 2020 16:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438528AbgDOUtI (ORCPT ); Wed, 15 Apr 2020 16:49:08 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 846D4C061A41 for ; Wed, 15 Apr 2020 13:49:08 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id c23so518691pgj.3 for ; Wed, 15 Apr 2020 13:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C6Z/2U1uSaMVZIS1zrhX5ycxTde0oQImP1UUauJl94M=; b=SwCYJ9CQNtNrDxPo10KzPwy/ANvNIUyE6IU+PI/Y+XyS4RgwDVTs1XDSRenCRHcku3 Oi60l1cNkELSfLeIKpssWjCQVNCvhzvgfn6oJ+fbDWK+j3YtHqyqmr7tg7YtSKyh4eAK Z8aPM7rIsVFLNioM2ldcrEmsmhrJ6xBk9rqzl8MNtmMONDQkv+F5ufxs6HxAWS6BjjXh +B9KnfjStoKp/m+c+xFBSyN8z19xirInrN7y/vAARQZPvphs3ZI7cR9DjMqfvWVfQFpi aL/YU2rLmGdPwYAUYRebovMZFb69mIbA+Xuyb2Qffj5fBGY/gL9DH7AGR8+ftf3nzOs4 qBWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C6Z/2U1uSaMVZIS1zrhX5ycxTde0oQImP1UUauJl94M=; b=i7CrGwddjCnkUvCKEyfUeUzztSYsYUBvWyxaBI0jlvIZPCJbHLYwlmvYnpUKxBdulG j+XQt4DQSJYMlfud+/eN6ZFaYRrxFKyMsi8xiF4h2Pvy8FNyEMBVHQ1twwjMpPIATW22 KBpb0p+7FiGcbGE8VcZVAA565eoMznhiPLRG+l3gKymHUSG6rzypfxoG+gmzlJv2hufe DGUzKaR1kTysTWhl4pn9HdxiVh2db1CPVOWor9SqjURwExErCwttjQjjHrW2nf8BcYgy fokccDNz0guCvKr/rolefnAMy+yG7LYCng6G2tIaDFP7cVCd4Yve+Dhi6eXEk+YaYE13 5HnA== X-Gm-Message-State: AGi0PuYFZYVR5k7i0re265a8X7rV/HhaSmqJe2zEGA4aonxbCgZ++G+u FEoxZWQSesKTQYk8orh0wAr9rg== X-Google-Smtp-Source: APiQypIFhtjeAMS9QbnUxPjJwRI1p5Xcbg5ltSm/cXWA2dMBCmxFwFxeAotaA6qLGbnm5f4z9vfiww== X-Received: by 2002:a62:58c6:: with SMTP id m189mr16314763pfb.161.1586983748099; Wed, 15 Apr 2020 13:49:08 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i13sm14461861pfa.113.2020.04.15.13.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:49:07 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] remoteproc: Restructure firmware name allocation Date: Wed, 15 Apr 2020 14:48:56 -0600 Message-Id: <20200415204858.2448-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org> References: <20200415204858.2448-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Improve the readability of function rproc_alloc_firmware() by using a non-negated condition. Suggested-by: Alex Elder Signed-off-by: Mathieu Poirier Reviewed-by: Alex Elder --- drivers/remoteproc/remoteproc_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ebaff496ef81..0bfa6998705d 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1984,14 +1984,14 @@ static int rproc_alloc_firmware(struct rproc *rproc, { const char *p; - if (!firmware) + if (firmware) + p = kstrdup_const(firmware, GFP_KERNEL); + else /* * If the caller didn't pass in a firmware name then * construct a default name. */ p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name); - else - p = kstrdup_const(firmware, GFP_KERNEL); if (!p) return -ENOMEM; From patchwork Wed Apr 15 20:48:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11492013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8D1C174A for ; Wed, 15 Apr 2020 20:49:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C05FF2076D for ; Wed, 15 Apr 2020 20:49:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TzRiq509" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442137AbgDOUtM (ORCPT ); Wed, 15 Apr 2020 16:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438666AbgDOUtJ (ORCPT ); Wed, 15 Apr 2020 16:49:09 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B960C0610D6 for ; Wed, 15 Apr 2020 13:49:09 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id d24so474725pll.8 for ; Wed, 15 Apr 2020 13:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ch0sqi4G1BQL+KPaSc+5TNiMX3GlnJ1H3XmGIgfMOXw=; b=TzRiq5093NXJ/0OqFqhCAj1qbVzGr7tW44nNbIxfJn/A7jqQ0/YCn84qTB2JPTu3DL dW+DctrYoXTvqFyhdCjgv4a58jhmbCuu3r7b7rq/ZRJ2ZxX7AJbgtKtkJ4DGAxCmpwwg eqIn8zHn98l8qFJC0IbL2sDsiu4OMaXUT1ycD374kEdeX9yupAnBZyZyml4z8ucDCPwD Y2F3oc5sTsDvpHpXH9LY3SWM0dyK7iHC7CpyUd8w0S8UqHre261ESBKTWMV3NTQ+wrQe qI/8cXkgx5n9oy9vDLJ68gy9s2b0Hk+FFcCliMe+4eY0IjOYb3Zsi93hU9dP/KTKH/Ox qCwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ch0sqi4G1BQL+KPaSc+5TNiMX3GlnJ1H3XmGIgfMOXw=; b=KKZX+PsTDRBNybh4/nrzcse2yMwSTFXkK74IkWzJF+oL81CZbZRIpQ82FylcjbGPD8 u29OsO/QSM0bzGz3CvGBhboM8E4SBIdL+71yCP9MK/oIL0IVfaEGIpG01Q0NBTUl+x3M c5vcUaI/uBw+8hJcSe1V/k9DyteAV0YEtD3DVVQaF9t8F0wETr/XvAv5WJlFGPeu8xfv lvBhmM/VDjacLtLvAYKnTztG1zRSyvM1ThJ+XpWe4bobLcPg5lZGrOedUYSlgZ0WvLQ/ N4DnIuTkgLfgzB62vowN4Rmsqd55zwszIxmpq6EQ2q31sRtx7IkBgD/oyEc6T9DKIo4i NzFA== X-Gm-Message-State: AGi0Pub5pZVJwZY4Nq3dd6bV+PN/d5t6AEClpDLBg2UwoDlrlt6cAguL s8+M/wzgttJVaLh46JuK5lvGqw== X-Google-Smtp-Source: APiQypJw0SHRb41jbv6PcjOXUYYXfOMslxfY0S2mxng747q472WCFQh7gfVpzkRFx/nVSkXdIcykvw== X-Received: by 2002:a17:902:fe09:: with SMTP id g9mr6587197plj.306.1586983749174; Wed, 15 Apr 2020 13:49:09 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i13sm14461861pfa.113.2020.04.15.13.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:49:08 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc() Date: Wed, 15 Apr 2020 14:48:57 -0600 Message-Id: <20200415204858.2448-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org> References: <20200415204858.2448-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Make the rproc_ops allocation a function on its own in an effort to clean up function rproc_alloc(). Signed-off-by: Mathieu Poirier Reviewed-by: Alex Elder --- drivers/remoteproc/remoteproc_core.c | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0bfa6998705d..a5a0ceb86b3f 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2001,6 +2001,25 @@ static int rproc_alloc_firmware(struct rproc *rproc, return 0; } +static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) +{ + rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); + if (!rproc->ops) + return -ENOMEM; + + /* Default to ELF loader if no load function is specified */ + if (!rproc->ops->load) { + rproc->ops->load = rproc_elf_load_segments; + rproc->ops->parse_fw = rproc_elf_load_rsc_table; + rproc->ops->find_loaded_rsc_table = + rproc_elf_find_loaded_rsc_table; + rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; + } + + return 0; +} + /** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device @@ -2040,8 +2059,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, if (rproc_alloc_firmware(rproc, name, firmware)) goto free_rproc; - rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); - if (!rproc->ops) + if (rproc_alloc_ops(rproc, ops)) goto free_firmware; rproc->name = name; @@ -2068,16 +2086,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, atomic_set(&rproc->power, 0); - /* Default to ELF loader if no load function is specified */ - if (!rproc->ops->load) { - rproc->ops->load = rproc_elf_load_segments; - rproc->ops->parse_fw = rproc_elf_load_rsc_table; - rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - if (!rproc->ops->sanity_check) - rproc->ops->sanity_check = rproc_elf32_sanity_check; - rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; - } - mutex_init(&rproc->lock); INIT_LIST_HEAD(&rproc->carveouts); From patchwork Wed Apr 15 20:48:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11492019 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 370D613B2 for ; Wed, 15 Apr 2020 20:49:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E30C206E9 for ; Wed, 15 Apr 2020 20:49:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rRvVXTP7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442157AbgDOUt0 (ORCPT ); Wed, 15 Apr 2020 16:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438385AbgDOUtK (ORCPT ); Wed, 15 Apr 2020 16:49:10 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BD13C061BD3 for ; Wed, 15 Apr 2020 13:49:10 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id w3so479208plz.5 for ; Wed, 15 Apr 2020 13:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5mMaRFdCaTH1ggi3Wx1BWKvNiF1AGQ87b+AkdJgmycY=; b=rRvVXTP7ZJzwJhf2Xmo3vX+8MSK3BDm3OT74D5LpCxb54uKGTRX9zNxmh53maUTuDX QlO9C4z4sCObkinTOLXaQQ+ON/0I1sFNi5yXsyhdqeKlYuAwtQsuQHGZSDpcEs++CmRK qUTQA/19pgl8Q8QVyB4puFqpgHqA0Exv6dun2x9Cq+/xlQ4DkG5CCTwpL98FIHzICtS5 h7X58oq3qlBvBk++0wFqy9DK1rAQ8b8rIbf2/t6WrA29SL2S0+KA/nuA6Ve25BVwYsZw on2Q0Gk50Y8gAB4vJN69edaImi8dwcmrW4q2wpJKBaOH/Ayk73r1TtNEUslfU+b/yFdl zx8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5mMaRFdCaTH1ggi3Wx1BWKvNiF1AGQ87b+AkdJgmycY=; b=aTZpsmGj19tII+W+BYL1Rrh+nBEoQt7i+HA0Qe71RFapiriiBod6CIy9IUxkgIo9WZ 0V4d8sGINPuxOtchjKV3Btluol5B2mn/hS9S9jA3SLSoAxww1XFy4xO4/HdoG4GhZ7c1 neVJBOFTbyyPZNFvbYeSvlzWR/AizHA5UucL6a9/JRLhsD8oVOmvUxtVFOetTWymSuyF kTw09WnaYjc2bg1n7wlDLthSOJJJCUQr7uQFxFLavwRGKIq1qGKK23LufNetWpI2IORR xMdkX4L2Es0FmLmI03GXaAgAyg92FqvB0vJ/gHjYlKafl0kSK/pduf9JUAXPcDIzEw0Y GEjA== X-Gm-Message-State: AGi0PuaKhjhoQFCllD4SKXq1lS9SF7eTg69Fy6wbl8cfA9v9OkOt4wQc MzzxjPpmhHT8HRVx8iKq44vyjw== X-Google-Smtp-Source: APiQypIEHhprsgf/g45tSL3P5lgi62wsjU6pB/U8o8/KQp+LhHz+Wmuz0Y2ljFPdYiZ7txC57NY54g== X-Received: by 2002:a17:902:8d86:: with SMTP id v6mr6861724plo.57.1586983750173; Wed, 15 Apr 2020 13:49:10 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i13sm14461861pfa.113.2020.04.15.13.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 13:49:09 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: s-anna@ti.com, elder@linaro.org, Markus.Elfring@web.de, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] remoteproc: Get rid of tedious error path Date: Wed, 15 Apr 2020 14:48:58 -0600 Message-Id: <20200415204858.2448-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415204858.2448-1-mathieu.poirier@linaro.org> References: <20200415204858.2448-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Get rid of tedious error management by moving firmware and operation allocation after calling device_initialize(). That way we take advantage of the automatic call to rproc_type_release() to cleanup after ourselves when put_device() is called. Signed-off-by: Mathieu Poirier Reviewed-by: Alex Elder Acked-by: Suman Anna --- drivers/remoteproc/remoteproc_core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index a5a0ceb86b3f..405c94f151a7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2056,12 +2056,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, if (!rproc) return NULL; - if (rproc_alloc_firmware(rproc, name, firmware)) - goto free_rproc; - - if (rproc_alloc_ops(rproc, ops)) - goto free_firmware; - rproc->name = name; rproc->priv = &rproc[1]; rproc->auto_boot = true; @@ -2074,12 +2068,17 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.driver_data = rproc; idr_init(&rproc->notifyids); + if (rproc_alloc_firmware(rproc, name, firmware)) + goto put_device; + + if (rproc_alloc_ops(rproc, ops)) + goto put_device; + /* Assign a unique device index and name */ rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL); if (rproc->index < 0) { dev_err(dev, "ida_simple_get failed: %d\n", rproc->index); - put_device(&rproc->dev); - return NULL; + goto put_device; } dev_set_name(&rproc->dev, "remoteproc%d", rproc->index); @@ -2100,11 +2099,8 @@ 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); +put_device: + put_device(&rproc->dev); return NULL; } EXPORT_SYMBOL(rproc_alloc);