Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17924294ybl; Thu, 2 Jan 2020 14:55:24 -0800 (PST) X-Google-Smtp-Source: APXvYqwguXqAqG1+u9aufxxgGoARGK0IyUWLmUmusHHu0KFQmsDFnJtvWjZ3LIRGFN0SG8MaLk9H X-Received: by 2002:a9d:3f61:: with SMTP id m88mr76550106otc.56.1578005724748; Thu, 02 Jan 2020 14:55:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005724; cv=none; d=google.com; s=arc-20160816; b=V/j+z1dng/rqQzluHKUFJU5/A6h94NwCIQbxWJH0Gvi4GeF7B+ouNfzb3Zt6wgOVme /M7pXaDpJQESpO20NpQqfwyeOnwbc0GVZmbmpwyyU7b2xB4bkenvm9uXPR8NN+7B8oFN YKQMLHc6/+LrDMNAb32lT5yF30xqUQI201t1vy61nOeloz/DU4e1E7msXr2ky87dAGxX /2LaBX5EhyslkvSbVzV3ZVCHEJiWI6w8XIdx79qVAeFa/zxgY+iyrlYifBw+RHOdmaKL wXq7hHvnVnPbx2BniUZReyrB9GZixVF4aUaCBoGv0AkaTW7zH+4oBjbbwKBLMh58hUvq fKKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6bjGfmvUsp6lB5+2kKHII4qLlaqh6XWn9KUQW6RbqeM=; b=T8osNbs4e0YexaQkJL1JrhlincNyb2t+NeWpiA1q0Pibtngj9Oig+mZr4NulvHpUF6 PourkWhyJqqYq3g4PjHYo/JkzGzLD1e/ruvDJiXuXXPERZYYigsgg7DquBl7hiFnOand OB+yszKX00JbPf5cN2nK8wlo7Gi8c2vKBUk3Rwqzww+wAbk9Luy+tOU2ODcvK86SiWrq c9q9rSYoXnRZYk06oIXebhgnuR1f3YVRn7CwxOuYddTayzDb6TzrLUK7nMvNu2N7WNni DcLbhR3gRMZq5oGPCqccP0aCBGGmrHfvJeN15/dQ2MQXiSn0RoOUEqXzDo2HJn26Ells 3r2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sPoP68wS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d192si27085417oig.21.2020.01.02.14.55.12; Thu, 02 Jan 2020 14:55:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sPoP68wS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728728AbgABWVG (ORCPT + 99 others); Thu, 2 Jan 2020 17:21:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:39582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728931AbgABWVD (ORCPT ); Thu, 2 Jan 2020 17:21:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E6FC021582; Thu, 2 Jan 2020 22:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003663; bh=IMSOtqcwaP6UlIqYmPsM13lnT/jot8oLkrsfRUmghbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sPoP68wSNv3TPcxrz0YtV6+MFhpfCkgOgQ0P0pVX3MchcJ1eYhtbGWvzkZCEIGJc1 XdbTICVQ74SGTyaFy3MNSUG55x45bUYXtIjNinjvRpaeasK61T7PTJ6FTq0+lz2xvF L9TqbxOO8jbhzg0Eu5TLLt8eifw18SBWnq1bIx+M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, Jens Axboe Cc: Greg Kroah-Hartman , stable@vger.kernel.org, linux-scsi@vger.kernel.org, =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= , Sasha Levin Subject: [PATCH 4.19 063/114] cdrom: respect device capabilities during opening action Date: Thu, 2 Jan 2020 23:07:15 +0100 Message-Id: <20200102220035.429538902@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Diego Elio Pettenò [ Upstream commit 366ba7c71ef77c08d06b18ad61b26e2df7352338 ] Reading the TOC only works if the device can play audio, otherwise these commands fail (and possibly bring the device to an unhealthy state.) Similarly, cdrom_mmc3_profile() should only be called if the device supports generic packet commands. To: Jens Axboe Cc: linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org Signed-off-by: Diego Elio Pettenò Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/cdrom/cdrom.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 933268b8d6a5..d3947388a3ef 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -996,6 +996,12 @@ static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks) tracks->xa = 0; tracks->error = 0; cd_dbg(CD_COUNT_TRACKS, "entering cdrom_count_tracks\n"); + + if (!CDROM_CAN(CDC_PLAY_AUDIO)) { + tracks->error = CDS_NO_INFO; + return; + } + /* Grab the TOC header so we can see how many tracks there are */ ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header); if (ret) { @@ -1162,7 +1168,8 @@ int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, ret = open_for_data(cdi); if (ret) goto err; - cdrom_mmc3_profile(cdi); + if (CDROM_CAN(CDC_GENERIC_PACKET)) + cdrom_mmc3_profile(cdi); if (mode & FMODE_WRITE) { ret = -EROFS; if (cdrom_open_write(cdi)) @@ -2882,6 +2889,9 @@ int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written) it doesn't give enough information or fails. then we return the toc contents. */ use_toc: + if (!CDROM_CAN(CDC_PLAY_AUDIO)) + return -ENOSYS; + toc.cdte_format = CDROM_MSF; toc.cdte_track = CDROM_LEADOUT; if ((ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &toc))) -- 2.20.1