From patchwork Sat Mar 3 12:20:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomoki Sekiyama X-Patchwork-Id: 10256073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3378D60211 for ; Sat, 3 Mar 2018 12:21:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0421228783 for ; Sat, 3 Mar 2018 12:21:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6BA828706; Sat, 3 Mar 2018 12:21:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6026428706 for ; Sat, 3 Mar 2018 12:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751811AbeCCMU6 (ORCPT ); Sat, 3 Mar 2018 07:20:58 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:40620 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751721AbeCCMU5 (ORCPT ); Sat, 3 Mar 2018 07:20:57 -0500 Received: by mail-pl0-f65.google.com with SMTP id i6-v6so7213598plt.7; Sat, 03 Mar 2018 04:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=O7YOWjxCWOmTePSwb3xdu0yVLYIMLfllip5jdBpE3a0=; b=CDhx+6t37RPkG/d5F+bZhm3BEjt8CMkbi97MMlFdVBtqUJdsQdK8+QuI+RYBpXWkIm QrWqisyGOZAYnjRHEbEOMDm5u6mGETSvYIvEaYaO+a75C+rmLrKiFdkLG+9QYZ2hBrNl Q07k0WTziq4K6zNaSGZ3yw1UD6PsgaFH6Me7zg/dKnc/RLpmT1cZuFj1MC89POxNOzrm kNZ91K/kigjhZ0Y2ivgNfmbJRsPVYyWa0yTzkiuQZQCT0zLhxueRQp4lBzv/wTIMgpWs Vkt7rneEb5jfGHmJclKKx81VKxphc+2jCRdhRHgqERaHch+G7fcb76ypIWVyuS4TR5vs WGkw== 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; bh=O7YOWjxCWOmTePSwb3xdu0yVLYIMLfllip5jdBpE3a0=; b=jiEQBe2KZJYDcjgjWJsdQOgf/3yoKETlA3+PX6KTlqNtXuL6CA8GfZYzOp+IY8DKhN F2YB5tct4jEJBy7yel/WK1NuqFGoAyalQM8ftEvQPksxwWpgqBC5c2onUsewoI0y70NF 0LGLAhDS5OjXvdwsgCzByI0E9ZbbVTfxzhQCTSLYBYMr+kV6S+yZwnjmodTKyn0xwf+9 tBV57cI4XO0VTZme0k+PuWHd1n6JHIXuG3y7dm1fbUR2bHr8u+tYwzeV1EaI4oKZm0Jz yqjPcqthRsqqGqg0pn3uRQ5WrjnugaKugdOE9Bko6jbTJFaDsbY/C6kLxrClEpqxd3Pe eIIA== X-Gm-Message-State: APf1xPC7oESN1N9kEjSxU/HmHN/Cu7wQdMWCxa6Uouu6BktXT8uR5Uov NYEard8dSbF/417cDiAOyA9twPl0 X-Google-Smtp-Source: AG47ELuwrBzf2H8AcDhQyrzK7Q28m7te7VJ8XsWLOqbJnrwOIC1I+DP/2G5It0fdOUvo9za14HZAAA== X-Received: by 2002:a17:902:57c6:: with SMTP id g6-v6mr7974912plj.358.1520079656758; Sat, 03 Mar 2018 04:20:56 -0800 (PST) Received: from localhost.localdomain ([2403:7800:c156:c400:1a03:73ff:fe32:9736]) by smtp.gmail.com with ESMTPSA id t16sm17194824pfm.69.2018.03.03.04.20.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 03 Mar 2018 04:20:56 -0800 (PST) From: tomoki.sekiyama@gmail.com To: mchehab@s-opensource.com Cc: elfring@users.sourceforge.net, tomoki.sekiyama@gmail.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] media: siano: Fix coherent memory allocation failure on arm64 Date: Sat, 3 Mar 2018 21:20:17 +0900 Message-Id: <20180303122017.32669-1-tomoki.sekiyama@gmail.com> X-Mailer: git-send-email 2.14.3 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tomoki Sekiyama On some architectures such as arm64, siano chip based TV-tuner USB devices are not recognized correctly due to coherent memory allocation failure with the following error: [ 663.556135] usbcore: deregistering interface driver smsusb [ 683.624809] smsusb:smsusb_probe: board id=18, interface number 0 [ 683.633530] smsusb:smsusb_init_device: smscore_register_device(...) failed, rc -12 [ 683.641501] smsusb:smsusb_probe: Device initialized with return code -12 [ 683.652978] smsusb: probe of 1-1:1.0 failed with error -12 This is caused by dma_alloc_coherent(NULL, ...) returning NULL in smscoreapi.c. To fix this error, usb_alloc_coherent() must be used for DMA memory allocation for USB devices in such architectures. v2: non-usb `device' is also be passed to dma_alloc_coherent() Signed-off-by: Tomoki Sekiyama --- drivers/media/common/siano/smscoreapi.c | 36 ++++++++++++++++++++++++--------- drivers/media/common/siano/smscoreapi.h | 2 ++ drivers/media/usb/siano/smsusb.c | 1 + 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c index c5c827e11b64..34622b562963 100644 --- a/drivers/media/common/siano/smscoreapi.c +++ b/drivers/media/common/siano/smscoreapi.c @@ -690,17 +690,24 @@ int smscore_register_device(struct smsdevice_params_t *params, /* alloc common buffer */ dev->common_buffer_size = params->buffer_size * params->num_buffers; - dev->common_buffer = dma_alloc_coherent(NULL, dev->common_buffer_size, - &dev->common_buffer_phys, - GFP_KERNEL | GFP_DMA); - if (!dev->common_buffer) { + if (params->usb_device) + buffer = usb_alloc_coherent(params->usb_device, + dev->common_buffer_size, + GFP_KERNEL | GFP_DMA, + &dev->common_buffer_phys); + else + buffer = dma_alloc_coherent(params->device, + dev->common_buffer_size, + &dev->common_buffer_phys, + GFP_KERNEL | GFP_DMA); + if (!buffer) { smscore_unregister_device(dev); return -ENOMEM; } + dev->common_buffer = buffer; /* prepare dma buffers */ - for (buffer = dev->common_buffer; - dev->num_buffers < params->num_buffers; + for (; dev->num_buffers < params->num_buffers; dev->num_buffers++, buffer += params->buffer_size) { struct smscore_buffer_t *cb; @@ -720,6 +727,7 @@ int smscore_register_device(struct smsdevice_params_t *params, dev->board_id = SMS_BOARD_UNKNOWN; dev->context = params->context; dev->device = params->device; + dev->usb_device = params->usb_device; dev->setmode_handler = params->setmode_handler; dev->detectmode_handler = params->detectmode_handler; dev->sendrequest_handler = params->sendrequest_handler; @@ -1231,10 +1239,18 @@ void smscore_unregister_device(struct smscore_device_t *coredev) pr_debug("freed %d buffers\n", num_buffers); - if (coredev->common_buffer) - dma_free_coherent(NULL, coredev->common_buffer_size, - coredev->common_buffer, coredev->common_buffer_phys); - + if (coredev->common_buffer) { + if (coredev->usb_device) + usb_free_coherent(coredev->usb_device, + coredev->common_buffer_size, + coredev->common_buffer, + coredev->common_buffer_phys); + else + dma_free_coherent(coredev->device, + coredev->common_buffer_size, + coredev->common_buffer, + coredev->common_buffer_phys); + } kfree(coredev->fw_buf); list_del(&coredev->entry); diff --git a/drivers/media/common/siano/smscoreapi.h b/drivers/media/common/siano/smscoreapi.h index 4cc39e4a8318..134c69f7ea7b 100644 --- a/drivers/media/common/siano/smscoreapi.h +++ b/drivers/media/common/siano/smscoreapi.h @@ -134,6 +134,7 @@ struct smscore_buffer_t { struct smsdevice_params_t { struct device *device; + struct usb_device *usb_device; int buffer_size; int num_buffers; @@ -176,6 +177,7 @@ struct smscore_device_t { void *context; struct device *device; + struct usb_device *usb_device; char devpath[32]; unsigned long device_flags; diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c index f13e4b01b5a5..3c605a573ce4 100644 --- a/drivers/media/usb/siano/smsusb.c +++ b/drivers/media/usb/siano/smsusb.c @@ -446,6 +446,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id) dev->in_ep, dev->out_ep); params.device = &dev->udev->dev; + params.usb_device = dev->udev; params.buffer_size = dev->buffer_size; params.num_buffers = MAX_BUFFERS; params.sendrequest_handler = smsusb_sendrequest;