From patchwork Thu Mar 24 23:27:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8666031 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-renesas-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 50C21C0553 for ; Thu, 24 Mar 2016 23:29:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A5ED720166 for ; Thu, 24 Mar 2016 23:29:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B50C7202BE for ; Thu, 24 Mar 2016 23:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752271AbcCXX2r (ORCPT ); Thu, 24 Mar 2016 19:28:47 -0400 Received: from galahad.ideasonboard.com ([185.26.127.97]:40281 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752041AbcCXX2c (ORCPT ); Thu, 24 Mar 2016 19:28:32 -0400 Received: from avalon.bb.dnainternet.fi (85-23-193-79.bb.dnainternet.fi [85.23.193.79]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id D1035202BA; Fri, 25 Mar 2016 00:27:24 +0100 (CET) From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org Subject: [PATCH 47/51] v4l: vsp1: dl: Fix race conditions Date: Fri, 25 Mar 2016 01:27:43 +0200 Message-Id: <1458862067-19525-48-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458862067-19525-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1458862067-19525-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 The vsp1_dl_list_put() function expects to be called with the display list manager lock held. This assumption is correct for calls from within the vsp1_dl.c file, but not for the external calls. Fix it by taking the lock inside the function and providing an unlocked version for the internal callers. Signed-off-by: Laurent Pinchart --- drivers/media/platform/vsp1/vsp1_dl.c | 41 +++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/vsp1/vsp1_dl.c b/drivers/media/platform/vsp1/vsp1_dl.c index 8efa5447c1b3..4f2c3c95bfa4 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.c +++ b/drivers/media/platform/vsp1/vsp1_dl.c @@ -164,25 +164,36 @@ struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm) return dl; } +/* This function must be called with the display list manager lock held.*/ +static void __vsp1_dl_list_put(struct vsp1_dl_list *dl) +{ + if (!dl) + return; + + dl->reg_count = 0; + + list_add_tail(&dl->list, &dl->dlm->free); +} + /** * vsp1_dl_list_put - Release a display list * @dl: The display list * * Release the display list and return it to the pool of free lists. * - * This function must be called with the display list manager lock held. - * * Passing a NULL pointer to this function is safe, in that case no operation * will be performed. */ void vsp1_dl_list_put(struct vsp1_dl_list *dl) { + unsigned long flags; + if (!dl) return; - dl->reg_count = 0; - - list_add_tail(&dl->list, &dl->dlm->free); + spin_lock_irqsave(&dl->dlm->lock, flags); + __vsp1_dl_list_put(dl); + spin_unlock_irqrestore(&dl->dlm->lock, flags); } void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, u32 data) @@ -220,7 +231,7 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl) */ update = !!(vsp1_read(vsp1, VI6_DL_BODY_SIZE) & VI6_DL_BODY_SIZE_UPD); if (update) { - vsp1_dl_list_put(dlm->pending); + __vsp1_dl_list_put(dlm->pending); dlm->pending = dl; goto done; } @@ -233,7 +244,7 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl) vsp1_write(vsp1, VI6_DL_BODY_SIZE, VI6_DL_BODY_SIZE_UPD | (dl->reg_count * 8)); - vsp1_dl_list_put(dlm->queued); + __vsp1_dl_list_put(dlm->queued); dlm->queued = dl; done: @@ -253,7 +264,7 @@ void vsp1_dlm_irq_display_start(struct vsp1_dl_manager *dlm) * processing by the device. The active display list, if any, won't be * accessed anymore and can be reused. */ - vsp1_dl_list_put(dlm->active); + __vsp1_dl_list_put(dlm->active); dlm->active = NULL; spin_unlock(&dlm->lock); @@ -265,7 +276,7 @@ void vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) spin_lock(&dlm->lock); - vsp1_dl_list_put(dlm->active); + __vsp1_dl_list_put(dlm->active); dlm->active = NULL; /* Header mode is used for mem-to-mem pipelines only. We don't need to @@ -328,9 +339,15 @@ void vsp1_dlm_setup(struct vsp1_device *vsp1) void vsp1_dlm_reset(struct vsp1_dl_manager *dlm) { - vsp1_dl_list_put(dlm->active); - vsp1_dl_list_put(dlm->queued); - vsp1_dl_list_put(dlm->pending); + unsigned long flags; + + spin_lock_irqsave(&dlm->lock, flags); + + __vsp1_dl_list_put(dlm->active); + __vsp1_dl_list_put(dlm->queued); + __vsp1_dl_list_put(dlm->pending); + + spin_unlock_irqrestore(&dlm->lock, flags); dlm->active = NULL; dlm->queued = NULL;