From patchwork Thu Feb 18 06:39:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 8346461 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8A3FC9F399 for ; Thu, 18 Feb 2016 06:39:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A0A5320395 for ; Thu, 18 Feb 2016 06:39:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8373820382 for ; Thu, 18 Feb 2016 06:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425297AbcBRGjQ (ORCPT ); Thu, 18 Feb 2016 01:39:16 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36220 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1425285AbcBRGjM (ORCPT ); Thu, 18 Feb 2016 01:39:12 -0500 Received: by mail-pf0-f170.google.com with SMTP id e127so25763212pfe.3 for ; Wed, 17 Feb 2016 22:39:12 -0800 (PST) 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; bh=aQy2y/jj0srruyL04CdXjZ1Ctn+B5Y5/xTMI2OBemR4=; b=QXec4pnrUy47KJrAbZCPye1ba+lLVBlTXRnDOLHO7gfRj7BHRjyyFp4YUwvlMgdO6Q EYNMleyFwUjaWOsgCzP830b3gJKL1pgLjSBQrJFlW45e5+KEkjAbcNwgZLT5quszCi9g COUSOb9lGfA3G+IlPYTtKd7mN8vY1xFOTNRd8= 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:in-reply-to :references; bh=aQy2y/jj0srruyL04CdXjZ1Ctn+B5Y5/xTMI2OBemR4=; b=WiNcPVVJASyI1OKlUoYrmW4tj3dvPs4XcPctNQbV26lZ0AcOTrIhRRA+6ssoMWFjBU SofwymTaqiJnnXs4H3LXic0JBl/a/ofslN7Z+8zEwxJpPU8jUmP3AuB9KQwcn21KrS73 MvEtY4+IWuwHL+nfeo56j7EHOujuSuNJ3hy4QBqQ/2RVAYdHZWm4SC6U8K0CVbcMU6U6 fQDit6REi0iSTIuZsipP+dxwgHAHhzos8DoyWLQGUllQ8xEFnxbeGi1eMlVpVtFpR+ra ofRex3ue8FtCgdvZNiUltEervlPjzRQoupBo/9tLtYYM1S3ta5YMpefa0e4QXLrnabyU KBGg== X-Gm-Message-State: AG10YOTFXVlDxmI5EwlyfYuhP/RoCK+PqDgUDr2+7XbMX23d/c2JgQjte+OusqfMBAu1rN9h X-Received: by 10.98.75.196 with SMTP id d65mr7896910pfj.96.1455777552019; Wed, 17 Feb 2016 22:39:12 -0800 (PST) Received: from tuxbot.san.rr.com (cpe-76-167-68-231.natsow.res.rr.com. [76.167.68.231]) by smtp.gmail.com with ESMTPSA id fl9sm7117315pab.30.2016.02.17.22.39.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 22:39:11 -0800 (PST) From: Bjorn Andersson To: Andy Gross , David Brown Cc: Srinivas Kandagatla , Fengwei Yin , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson Subject: [PATCH v3 3/5] soc: qcom: smd: Refactor channel open and close handling Date: Wed, 17 Feb 2016 22:39:04 -0800 Message-Id: <1455777546-19280-4-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455777546-19280-1-git-send-email-bjorn.andersson@linaro.org> References: <1455777546-19280-1-git-send-email-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Bjorn Andersson Refactor opening and closing of channels into two separate functions instead of open coding this in the various places. Signed-off-by: Bjorn Andersson Signed-off-by: Bjorn Andersson --- Changes since v2: - None Changes since v1: - New patch drivers/soc/qcom/smd.c | 62 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/drivers/soc/qcom/smd.c b/drivers/soc/qcom/smd.c index e8972ddfee85..d253e5cc233f 100644 --- a/drivers/soc/qcom/smd.c +++ b/drivers/soc/qcom/smd.c @@ -808,18 +808,12 @@ static int qcom_smd_dev_match(struct device *dev, struct device_driver *drv) } /* - * Probe the smd client. - * - * The remote side have indicated that it want the channel to be opened, so - * complete the state handshake and probe our client driver. + * Helper for opening a channel */ -static int qcom_smd_dev_probe(struct device *dev) +static int qcom_smd_channel_open(struct qcom_smd_channel *channel, + qcom_smd_cb_t cb) { - struct qcom_smd_device *qsdev = to_smd_device(dev); - struct qcom_smd_driver *qsdrv = to_smd_driver(dev); - struct qcom_smd_channel *channel = qsdev->channel; size_t bb_size; - int ret; /* * Packets are maximum 4k, but reduce if the fifo is smaller @@ -829,11 +823,44 @@ static int qcom_smd_dev_probe(struct device *dev) if (!channel->bounce_buffer) return -ENOMEM; - qcom_smd_channel_set_callback(channel, qsdrv->callback); + qcom_smd_channel_set_callback(channel, cb); qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING); - qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED); + return 0; +} + +/* + * Helper for closing and resetting a channel + */ +static void qcom_smd_channel_close(struct qcom_smd_channel *channel) +{ + qcom_smd_channel_set_callback(channel, NULL); + + kfree(channel->bounce_buffer); + channel->bounce_buffer = NULL; + + qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED); + qcom_smd_channel_reset(channel); +} + +/* + * Probe the smd client. + * + * The remote side have indicated that it want the channel to be opened, so + * complete the state handshake and probe our client driver. + */ +static int qcom_smd_dev_probe(struct device *dev) +{ + struct qcom_smd_device *qsdev = to_smd_device(dev); + struct qcom_smd_driver *qsdrv = to_smd_driver(dev); + struct qcom_smd_channel *channel = qsdev->channel; + int ret; + + ret = qcom_smd_channel_open(channel, qsdrv->callback); + if (ret) + return ret; + ret = qsdrv->probe(qsdev); if (ret) goto err; @@ -845,11 +872,7 @@ static int qcom_smd_dev_probe(struct device *dev) err: dev_err(&qsdev->dev, "probe failed\n"); - qcom_smd_channel_set_callback(channel, NULL); - kfree(channel->bounce_buffer); - channel->bounce_buffer = NULL; - - qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED); + qcom_smd_channel_close(channel); return ret; } @@ -886,12 +909,7 @@ static int qcom_smd_dev_remove(struct device *dev) * The client is now gone, cleanup and reset the channel state. */ channel->qsdev = NULL; - kfree(channel->bounce_buffer); - channel->bounce_buffer = NULL; - - qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED); - - qcom_smd_channel_reset(channel); + qcom_smd_channel_close(channel); return 0; }