From patchwork Wed Oct 19 00:23:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 78148 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1142972qge; Tue, 18 Oct 2016 17:24:02 -0700 (PDT) X-Received: by 10.98.80.2 with SMTP id e2mr5536611pfb.183.1476836642316; Tue, 18 Oct 2016 17:24:02 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t5si31529053paz.64.2016.10.18.17.24.02; Tue, 18 Oct 2016 17:24:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936411AbcJSAX7 (ORCPT + 27 others); Tue, 18 Oct 2016 20:23:59 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35277 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932525AbcJSAXs (ORCPT ); Tue, 18 Oct 2016 20:23:48 -0400 Received: by mail-pf0-f170.google.com with SMTP id s8so5009129pfj.2 for ; Tue, 18 Oct 2016 17:23:48 -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; bh=4SVOa7CNhLyz7vVld0pWh8QQws336xG+22WAEc3RJlg=; b=PndOK8BxzXXi1JShoR/oUHBuu4XAwDBmcE/n9E86m1zXxDbp3YbAHQrvKOCAj/FGDr LUmNA80t06C/FDniVsilmlN6e9DxfbN/sELWb5fI6U9BGaPDj9uAdFqWX0s2PwfGSjCA GFet32sHnYSlxmfO3uLldoIBiZbyGF/lVGm6I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4SVOa7CNhLyz7vVld0pWh8QQws336xG+22WAEc3RJlg=; b=k5dq+/R9dWJRHSyrBZVfL9Ajydaz/rqj0UJ2mWqHhEJ+9JDvJR7Dun7x84R3Ja56Z1 NMbLFX+Am2SlL24p5JZDR8IZA+ElDTbZe0B5f6stkV+D8GecDr8yGPy1qu4Z61oCSHvd CsP2tZ1LIKI4XEDjOEKmSWQ5b7S9sKwFT4qxnC/8+y98i8grD9ifRRm+5ON21TAgKXrZ 5MtM38gPuXrWskuDz5RkG3N+KmtnppK4dTjpCNKx06cmRg+un4xT/yg1NELBjTtt06R+ FqqNgz5/GR7rXLlMWEn1O3AeAOiLAVoQxdjzGQn3nR+W5AGl5izM1hOsWb+RbpNYbqm9 CfoA== X-Gm-Message-State: AA6/9RnQCMr5BSRMnH9YZSt+FgKbA9vp71dWCVcSteA4ouGY0BgpesEHHuaHH5r92UbM0TFi X-Received: by 10.98.149.74 with SMTP id p71mr5519281pfd.126.1476836628134; Tue, 18 Oct 2016 17:23:48 -0700 (PDT) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id e191sm58521239pfc.36.2016.10.18.17.23.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Oct 2016 17:23:46 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Loic Pallardy Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rpmsg: Handle invalid parameters in public API Date: Tue, 18 Oct 2016 17:23:44 -0700 Message-Id: <1476836624-342-1-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two cases of possible uninitialized pointer usage in the API, either the parameters themselves are invalid or we're trying to jump to functions not required to be implemented by all backends. Suggested-by: Loic Pallardy Signed-off-by: Bjorn Andersson --- drivers/rpmsg/rpmsg_core.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) -- 2.5.0 diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 7561941ba413..a79cb5a9e5f2 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -71,6 +71,9 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo) { + if (WARN_ON(!rpdev)) + return ERR_PTR(-EINVAL); + return rpdev->ops->create_ept(rpdev, cb, priv, chinfo); } EXPORT_SYMBOL(rpmsg_create_ept); @@ -80,11 +83,13 @@ EXPORT_SYMBOL(rpmsg_create_ept); * @ept: endpoing to destroy * * Should be used by drivers to destroy an rpmsg endpoint previously - * created with rpmsg_create_ept(). + * created with rpmsg_create_ept(). As with other types of "free" NULL + * is a valid parameter. */ void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) { - ept->ops->destroy_ept(ept); + if (ept) + ept->ops->destroy_ept(ept); } EXPORT_SYMBOL(rpmsg_destroy_ept); @@ -108,6 +113,11 @@ EXPORT_SYMBOL(rpmsg_destroy_ept); */ int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) { + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->send) + return -ENXIO; + return ept->ops->send(ept, data, len); } EXPORT_SYMBOL(rpmsg_send); @@ -132,6 +142,11 @@ EXPORT_SYMBOL(rpmsg_send); */ int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->sendto) + return -ENXIO; + return ept->ops->sendto(ept, data, len, dst); } EXPORT_SYMBOL(rpmsg_sendto); @@ -159,6 +174,11 @@ EXPORT_SYMBOL(rpmsg_sendto); int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len) { + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->send_offchannel) + return -ENXIO; + return ept->ops->send_offchannel(ept, src, dst, data, len); } EXPORT_SYMBOL(rpmsg_send_offchannel); @@ -182,6 +202,11 @@ EXPORT_SYMBOL(rpmsg_send_offchannel); */ int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) { + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->trysend) + return -ENXIO; + return ept->ops->trysend(ept, data, len); } EXPORT_SYMBOL(rpmsg_trysend); @@ -205,6 +230,11 @@ EXPORT_SYMBOL(rpmsg_trysend); */ int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->trysendto) + return -ENXIO; + return ept->ops->trysendto(ept, data, len, dst); } EXPORT_SYMBOL(rpmsg_trysendto); @@ -231,6 +261,11 @@ EXPORT_SYMBOL(rpmsg_trysendto); int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len) { + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->trysend_offchannel) + return -ENXIO; + return ept->ops->trysend_offchannel(ept, src, dst, data, len); } EXPORT_SYMBOL(rpmsg_trysend_offchannel);