Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp607834rwb; Wed, 18 Jan 2023 23:43:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXucUXH74MlUfAE//ADEsFo3+dbmFP33ByrGg2j8Kb5hVbPl2Q/u2cafTMVxtg7IQcTCs6Ri X-Received: by 2002:a17:90a:9a1:b0:229:72f1:18c0 with SMTP id 30-20020a17090a09a100b0022972f118c0mr10322130pjo.30.1674114209978; Wed, 18 Jan 2023 23:43:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674114209; cv=none; d=google.com; s=arc-20160816; b=RuygFTid/qAKi4jJ67tIdvTeMw2vf3vXQXAhp1PcDwLYKJHH/2GSojxgqpSK48tpa8 8hR3EtpJGDWYWFsnndCKw2fM3cjP+yOdsbFTXKtD2PG+PIoa5BTekvm9Kzy6Crk9JZXI VkjSTfCWkgAB9Tq4HdGMBA7pC6vECEgz1Z9Fs3gmcb3mt1EiGnWKeKypQ7exXirOAE0a XuD8XECGLQ9dfm/Bh1Kcg2eWjMVlxy3/a9TYRGpcE3RGDz52wl0+rQJ7GdFNABZHhauF 5UtDSl9wdhjIZX9i6RF1/uqhxC8TUV692KNysjKnv1ZwUrAmAHnbnD/mWGKQfmde0pb7 LZeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VqAzbLLYDseDH0aFLZJIW14txJxVr4Q7ny9rkhD2g6s=; b=KQuh/a/2xVmI5GhIZetReqihZK+BD0XftMi/uET6pXpaq2kdRsCNLk549dP/RQ//2c ARw7XqdPk/4JKcmDuuHbPUeN7OIoG6OuVyKOue5LC9lS09SXzXGjKE1zRWR0X2syAYnF 2ivsCeQAXlXMLY26syI45ESJypkuKg7OaC3J0v8wE50GRwXCrU7A41SvOBsRKgBngen+ TXrSXzLALeQFaX677BcPWd0hlUQt8wkhAUTCNl976KPKQZm6ZEiVqZ0YeMdD323rg07B UljShfVKbBbLgwojE48iARSYjyrN5e7lB2nR+SG9agavE+peif6mxwPcLJAvPOfa5H21 KbWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fwSFWCA3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob1-20020a17090b390100b00229a89f4db0si4690102pjb.153.2023.01.18.23.43.24; Wed, 18 Jan 2023 23:43:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fwSFWCA3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbjASHYX (ORCPT + 43 others); Thu, 19 Jan 2023 02:24:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbjASHYE (ORCPT ); Thu, 19 Jan 2023 02:24:04 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE18F61D65 for ; Wed, 18 Jan 2023 23:23:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674113036; x=1705649036; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9EfKDqwT5iUG/3vSHRo63HrB7tHmjW3+OTAvgNE6xiU=; b=fwSFWCA3VoaA+T3ht/94ELuEjUP++xTsHwrnz+eOMokFII9xJ8Jm6uYC dEdIltuHUA6TW1NxSb28QqERTluvlhqRg0o1txLuBDH5Q5HdHwYz7N3KC Efuf308thWRbWBK3WpCBdP/9IVCLzoDlppeVHBhArZn98YnoHUo08avE8 8rw22lqc27GcT35CK8C00F6IHFMGXH5APdrd8amHHTpaDmw55zvSKvX15 Yt3ISuh3+Jb6mBqMEmi4vUYoKXID8NXzY/PGDyNAe79yT2SANqEp1zcTc UUQ4faZGBgzFmjFk+9cKg/ALFmtOtMvbOGcDTtxeQA8LLDHFhvvW6nYm1 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10594"; a="322902678" X-IronPort-AV: E=Sophos;i="5.97,228,1669104000"; d="scan'208";a="322902678" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2023 23:23:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10594"; a="662028041" X-IronPort-AV: E=Sophos;i="5.97,228,1669104000"; d="scan'208";a="662028041" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2023 23:23:44 -0800 From: Bard Liao To: alsa-devel@alsa-project.org, vkoul@kernel.org Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, bard.liao@intel.com Subject: [PATCH v2 3/4] soundwire: cadence: use directly bus sdw_defer structure Date: Thu, 19 Jan 2023 15:32:10 +0800 Message-Id: <20230119073211.85979-4-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230119073211.85979-1-yung-chuan.liao@linux.intel.com> References: <20230119073211.85979-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pierre-Louis Bossart Copying the bus sdw_defer structure into the Cadence internals leads to using stale pointers and kernel oopses on errors. It's just simpler and safer to use the bus sdw_defer structure directly. Link: https://github.com/thesofproject/linux/issues/4056 Signed-off-by: Pierre-Louis Bossart Reviewed-by: Ranjani Sridharan Signed-off-by: Bard Liao --- drivers/soundwire/bus.c | 2 +- drivers/soundwire/cadence_master.c | 17 ++++++++--------- drivers/soundwire/cadence_master.h | 5 +---- include/linux/soundwire/sdw.h | 3 +-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 572cc9a9af41..fc192d0c61e7 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -237,7 +237,7 @@ static inline int do_transfer_defer(struct sdw_bus *bus, init_completion(&defer->complete); for (i = 0; i <= retry; i++) { - resp = bus->ops->xfer_msg_defer(bus, msg, defer); + resp = bus->ops->xfer_msg_defer(bus, msg); ret = find_response_code(resp); /* if cmd is ok or ignored return */ if (ret == 0 || ret == -ENODATA) diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c index 521387322145..2365395cb181 100644 --- a/drivers/soundwire/cadence_master.c +++ b/drivers/soundwire/cadence_master.c @@ -750,7 +750,7 @@ EXPORT_SYMBOL(cdns_xfer_msg); enum sdw_command_response cdns_xfer_msg_defer(struct sdw_bus *bus, - struct sdw_msg *msg, struct sdw_defer *defer) + struct sdw_msg *msg) { struct sdw_cdns *cdns = bus_to_cdns(bus); int cmd = 0, ret; @@ -763,9 +763,6 @@ cdns_xfer_msg_defer(struct sdw_bus *bus, if (ret) return SDW_CMD_FAIL_OTHER; - cdns->defer = defer; - cdns->defer->length = msg->len; - return _cdns_xfer_msg(cdns, msg, cmd, 0, msg->len, true); } EXPORT_SYMBOL(cdns_xfer_msg_defer); @@ -893,13 +890,15 @@ irqreturn_t sdw_cdns_irq(int irq, void *dev_id) return IRQ_NONE; if (int_status & CDNS_MCP_INT_RX_WL) { + struct sdw_bus *bus = &cdns->bus; + struct sdw_defer *defer = &bus->defer_msg; + cdns_read_response(cdns); - if (cdns->defer) { - cdns_fill_msg_resp(cdns, cdns->defer->msg, - cdns->defer->length, 0); - complete(&cdns->defer->complete); - cdns->defer = NULL; + if (defer && defer->msg) { + cdns_fill_msg_resp(cdns, defer->msg, + defer->length, 0); + complete(&defer->complete); } else { complete(&cdns->tx_complete); } diff --git a/drivers/soundwire/cadence_master.h b/drivers/soundwire/cadence_master.h index fa9dc38264a4..53029d22822d 100644 --- a/drivers/soundwire/cadence_master.h +++ b/drivers/soundwire/cadence_master.h @@ -109,7 +109,6 @@ struct sdw_cdns_dai_runtime { * @instance: instance number * @response_buf: SoundWire response buffer * @tx_complete: Tx completion - * @defer: Defer pointer * @ports: Data ports * @num_ports: Total number of data ports * @pcm: PCM streams @@ -130,7 +129,6 @@ struct sdw_cdns { u32 response_buf[CDNS_MCP_IP_MAX_CMD_LEN + 2]; struct completion tx_complete; - struct sdw_defer *defer; struct sdw_cdns_port *ports; int num_ports; @@ -189,8 +187,7 @@ enum sdw_command_response cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg); enum sdw_command_response -cdns_xfer_msg_defer(struct sdw_bus *bus, - struct sdw_msg *msg, struct sdw_defer *defer); +cdns_xfer_msg_defer(struct sdw_bus *bus, struct sdw_msg *msg); u32 cdns_read_ping_status(struct sdw_bus *bus); diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index 3cd2a761911f..fb2bd1524a26 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -852,8 +852,7 @@ struct sdw_master_ops { enum sdw_command_response (*xfer_msg) (struct sdw_bus *bus, struct sdw_msg *msg); enum sdw_command_response (*xfer_msg_defer) - (struct sdw_bus *bus, struct sdw_msg *msg, - struct sdw_defer *defer); + (struct sdw_bus *bus, struct sdw_msg *msg); enum sdw_command_response (*reset_page_addr) (struct sdw_bus *bus, unsigned int dev_num); int (*set_bus_conf)(struct sdw_bus *bus, -- 2.25.1