From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35B56C433F5 for ; Tue, 12 Oct 2021 13:51:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1462B60E9C for ; Tue, 12 Oct 2021 13:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237077AbhJLNxE (ORCPT ); Tue, 12 Oct 2021 09:53:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27765 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237056AbhJLNw7 (ORCPT ); Tue, 12 Oct 2021 09:52:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634046657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Lpesmbio9FZ09q7H/hgYyh50fUJ7X8y/Z2CXk6CH2Hw=; b=cHIH/jD6oXD2L9FLu+pR7146TxFkk3TwgNGMEvp+dcq3vPa5wkV0rCLMSzDSEP0sThj7Q9 t2no58uzzcCvMtvk2A+Fhu03NRP5/SW3ypycSlf2WQzBkkDdC4lEzGyg/zVBFm/EVjiPfr gRZeTUZObkwzcNmg42A1PVSBBpLOh1o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-7pqmE2CPNr-Jp9MqPCNWFg-1; Tue, 12 Oct 2021 09:50:52 -0400 X-MC-Unique: 7pqmE2CPNr-Jp9MqPCNWFg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BBEE29126B; Tue, 12 Oct 2021 13:50:50 +0000 (UTC) Received: from localhost (unknown [10.39.193.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4468760BF4; Tue, 12 Oct 2021 13:50:50 +0000 (UTC) From: Cornelia Huck To: Halil Pasic Cc: Pierre Morel , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Michael Mueller , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, bfu@redhat.com, Halil Pasic Subject: Re: [RFC PATCH 1/1] s390/cio: make ccw_device_dma_* more robust In-Reply-To: <20211011204837.7617301b.pasic@linux.ibm.com> Organization: Red Hat GmbH References: <20211011115955.2504529-1-pasic@linux.ibm.com> <466de207-e88d-ea93-beec-fbfe10e63a26@linux.ibm.com> <874k9ny6k6.fsf@redhat.com> <20211011204837.7617301b.pasic@linux.ibm.com> User-Agent: Notmuch/0.32.1 (https://notmuchmail.org) Date: Tue, 12 Oct 2021 15:50:48 +0200 Message-ID: <87pmsawdvr.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 11 2021, Halil Pasic wrote: > On Mon, 11 Oct 2021 16:33:45 +0200 > Cornelia Huck wrote: > >> On Mon, Oct 11 2021, Pierre Morel wrote: >> >> > On 10/11/21 1:59 PM, Halil Pasic wrote: >> >> diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c >> >> index 0fe7b2f2e7f5..c533d1dadc6b 100644 >> >> --- a/drivers/s390/cio/device_ops.c >> >> +++ b/drivers/s390/cio/device_ops.c >> >> @@ -825,13 +825,23 @@ EXPORT_SYMBOL_GPL(ccw_device_get_chid); >> >> */ >> >> void *ccw_device_dma_zalloc(struct ccw_device *cdev, size_t size) >> >> { >> >> - return cio_gp_dma_zalloc(cdev->private->dma_pool, &cdev->dev, size); >> >> + void *addr; >> >> + >> >> + if (!get_device(&cdev->dev)) >> >> + return NULL; >> >> + addr = cio_gp_dma_zalloc(cdev->private->dma_pool, &cdev->dev, size); >> >> + if (IS_ERR_OR_NULL(addr)) >> > >> > I can be wrong but it seems that only dma_alloc_coherent() used in >> > cio_gp_dma_zalloc() report an error but the error is ignored and used as >> > a valid pointer. >> >> Hm, I thought dma_alloc_coherent() returned either NULL or a valid >> address? > > Yes, that is what is documented. > >> >> > >> > So shouldn't we modify this function and just test for a NULL address here? >> >> If I read cio_gp_dma_zalloc() correctly, we either get NULL or a valid >> address, so yes. >> > > I don't think the extra care will hurt us too badly. I prefer to keep > the IS_ERR_OR_NULL() check because it needs less domain specific > knowledge to be understood, and because it is more robust. It feels weird, though -- I'd rather have a comment that tells me exactly what cio_gp_dma_zalloc() is supposed to return; I would have expected that a _zalloc function always gives me a valid pointer or NULL.