Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2448894pxb; Tue, 12 Oct 2021 06:55:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL6ztxE8GLSxzlZwkCSNmDk2mUuBEtTSj/oJve+yzWpNvjmXvclv7au10fLW4pJpWPO1Lb X-Received: by 2002:a50:d989:: with SMTP id w9mr33210edj.99.1634046924986; Tue, 12 Oct 2021 06:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634046924; cv=none; d=google.com; s=arc-20160816; b=VNJHjpNYp2ih1cwxj3pLXXUiEpA2WinWqd/kCY2NGb50dDXtL/LKCDK3MZ2rex0UgN M/k1lTLa61EsjdrrrotFE2NQcpeFSw2gNatgiU4Uzcj+ErS8tFw8bLV74Aww6HovZtcN ICUyql9mYvgIClVGBo5pFjG3bKqtE6xlElXVz3zKbYYw/2PdAKQDd2ajhBbM+yVwoUfv czg78tEOAMDaHw4ImdcIGdgDo2Ewtr5HghCSp9nxroPIi4nxWUGJa/80zpGyg//AHlv/ Uk+LylVM5c81vrElb87tzRjqe/iC3K0hmr8nlLwv6+7+TMRNZWq/NbGiVLQIm8XEezJd g+YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:user-agent :references:organization:in-reply-to:subject:cc:to:from :dkim-signature; bh=Lpesmbio9FZ09q7H/hgYyh50fUJ7X8y/Z2CXk6CH2Hw=; b=mMNBGd3ZnrURzcCq1DQS9kthSe2sTYxydoHwxa67qOZydD0N32fhNl5J5/gNG2rAss qb1Uglo5SsywrvKWt+Iv/AeLwufmPyuMsoPydNtyBpw2JMGYGoF7Dkr7qmf9RofxQRD6 77w9heXs34gWTnhrpxRT7QNemSUWrKRmE8tuVtEipR6ke4cKfmUEdDkg4zA07V43xdXU Vjf76z4XTMhyZoqTq8LgrclDGkGV7EIXO74IsIJ+m9MIYgHpk9QKAhvX+iyivAzy8tr8 lPTZ1rThLJTMjAjq+yhEdGK0E8V5JrIxcaYJL99GhzIad+PxTHVE730U0WYp9A51KA7j 7iXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="cHIH/jD6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hg2si2042191ejc.538.2021.10.12.06.54.57; Tue, 12 Oct 2021 06:55:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="cHIH/jD6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237055AbhJLNxC (ORCPT + 99 others); Tue, 12 Oct 2021 09:53:02 -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.