Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1813015rdd; Thu, 11 Jan 2024 09:56:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHt5vXBBeUAcagY2sKfr6mhDBmrw3l9OJzqehl1K9GBtjxSrQE7u4OZ32+nAv6+64p+AM52 X-Received: by 2002:ac8:5a04:0:b0:429:bf14:bfcc with SMTP id n4-20020ac85a04000000b00429bf14bfccmr133716qta.20.1704995769251; Thu, 11 Jan 2024 09:56:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704995769; cv=none; d=google.com; s=arc-20160816; b=pPkL2sncRVvF3HeJQw20Gkegqi1SR9Oo8KtxhQn0Xt7yNCsRzd0dWf3T2Il6+t0jyj vMhDma656gA5Ey54L8il9EQVbmvmjVmKaA9f7WX/gkEKfR4edTD7Oje6QAEOpzYNuS4V p1nGlHzKs0mdHqVFmyo2hMfo3byoLoaGg2aKbI4X/0jI/cGro4fS8ObmMOesspjR1Ehm kU4/OMeq5vrxVbbc7QAIYht+v7ggSl4B17/+pbfqgQvoX29D7gUrGLGx79S9l5Y4xAaP 7s0ubra7trWaHjcwWARI2s6c4k52/Urz5cuXUuNlIKoJfegd/ooJC89Hl3jQrz1Ogfey EZQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=n9arcEUo79iuH5i+dQJ8o/Ftr9e8e+zqckCAA6/vHao=; fh=pmFPCYiRB06p9Y6LPe9YYbmJBI1ey07imhyk52UM8LE=; b=GE8r+rvJ8h5vJtlocJ+WScRCO0EuGLWcrNpCUaCr2wTpNAAh5SyfjuP20DNQZfi+J5 neVcaIBtLkqHntO50wEBLzYEEfb46OaQEMY5cnd4Clu9svrGl6emH0tVCumU7zGY/GJB auVeD85SiHblB69wXEeojn6KUnsnf2iphz9AuuGcGpNAvsSPWcE76zYreGhe4F2et3D0 OA2MfzAwAaBxR5a+cGemSL5bTGj9tuk2lvk5EiHZg4p1woCax/XIC0OXWfHGAnueu0cV lpvd6UTz+RXnoSy12nasKBaqlcDkjeXRMQp0bHWVfJS5yQcX+NhBZpTPGOyG40cH9vGb RKkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23952-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23952-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=acm.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u7-20020a05622a17c700b00429c8edff39si768954qtk.270.2024.01.11.09.56.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 09:56:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23952-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23952-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23952-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=acm.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 024E81C2448F for ; Thu, 11 Jan 2024 17:56:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78B08537E3; Thu, 11 Jan 2024 17:56:01 +0000 (UTC) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48E8452F6A; Thu, 11 Jan 2024 17:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1d426ad4433so36044285ad.0; Thu, 11 Jan 2024 09:55:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704995757; x=1705600557; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n9arcEUo79iuH5i+dQJ8o/Ftr9e8e+zqckCAA6/vHao=; b=KkEZCKXgczUxYmGnsgzbrQajIB3ag9cDauf3ow20j+Cdh7gSiBnsei0R7Ycs0ThJwN RKEs/2KoOkljZS2+dKNmqoUfpG4sm6BsKyDpB5HqBGZ1ZdNyJETkdz7KdZVA/4JAKRpZ YDh0tVKiCpAJIFpJcHy0rVpSeXQN/P12SeSTLv60wMo03RKt201cuHolOh3qNbTTJhQb yBzg567e7BfZpPBUfyCVZktMhACllh4nKn9ace+9lIDClLr6Y48NOEnp/WDxPQqtUm2A QTNQwgb5nGo1Qdi4Sh1lreHtrhmlShko0FHOp+uI4Sw5tWBFBm8tKsSu3ihqJoAYfMfI Wq0g== X-Gm-Message-State: AOJu0Yy5GmRRjk+a1LN+Y7R8vOf7nAw2G9xmeR8JkLRDRgxKLUt8as70 eyubw55ilA578VcfQfYh7Ak= X-Received: by 2002:a05:6a20:3c91:b0:19a:41b2:7d98 with SMTP id b17-20020a056a203c9100b0019a41b27d98mr210749pzj.89.1704995757236; Thu, 11 Jan 2024 09:55:57 -0800 (PST) Received: from ?IPV6:2620:0:1000:8411:2b84:6ee3:e813:3d8d? ([2620:0:1000:8411:2b84:6ee3:e813:3d8d]) by smtp.gmail.com with ESMTPSA id u25-20020a62d459000000b006db056542e6sm1500847pfl.190.2024.01.11.09.55.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jan 2024 09:55:56 -0800 (PST) Message-ID: <5b643088-7110-494e-9c5b-dd271c291894@acm.org> Date: Thu, 11 Jan 2024 09:55:54 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] scsi: core: Safe warning about bad dev info string Content-Language: en-US To: Petr Mladek , "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Down , oe-kbuild-all@lists.linux.dev, kernel test robot References: <20240111162419.12406-1-pmladek@suse.com> From: Bart Van Assche In-Reply-To: <20240111162419.12406-1-pmladek@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/11/24 08:24, Petr Mladek wrote: > Both "model" and "strflags" are passed to "%s" even when one or both > are NULL. > > It is safe because vsprintf() would detect the NULL pointer and print > "(null)". But it is a kernel-specific feature and compiler warns > about it: > > > In file included from include/linux/kernel.h:19, > from arch/x86/include/asm/percpu.h:27, > from arch/x86/include/asm/current.h:6, > from include/linux/sched.h:12, > from include/linux/blkdev.h:5, > from drivers/scsi/scsi_devinfo.c:3: > drivers/scsi/scsi_devinfo.c: In function 'scsi_dev_info_list_add_str': >>> include/linux/printk.h:434:44: warning: '%s' directive argument is null [-Wformat-overflow=] > 434 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) > | ^ > include/linux/printk.h:430:3: note: in definition of macro 'printk_index_wrap' > 430 | _p_func(_fmt, ##__VA_ARGS__); \ > | ^~~~~~~ > drivers/scsi/scsi_devinfo.c:551:4: note: in expansion of macro 'printk' > 551 | printk(KERN_ERR "%s: bad dev info string '%s' '%s'" > | ^~~~~~ > drivers/scsi/scsi_devinfo.c:552:14: note: format string is defined here > 552 | " '%s'\n", __func__, vendor, model, > | ^~ > > > Do not rely on the kernel specific behavior and print the message a safe way. > > Reported-by: kernel test robot > Closes: https://lore.kernel.org/oe-kbuild-all/202401112002.AOjwMNM0-lkp@intel.com/ > Signed-off-by: Petr Mladek > --- > Note: The patch is only compile tested. > > drivers/scsi/scsi_devinfo.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c > index 3fcaf10a9dfe..ba7237e83863 100644 > --- a/drivers/scsi/scsi_devinfo.c > +++ b/drivers/scsi/scsi_devinfo.c > @@ -551,9 +551,9 @@ static int scsi_dev_info_list_add_str(char *dev_list) > if (model) > strflags = strsep(&next, next_check); > if (!model || !strflags) { > - printk(KERN_ERR "%s: bad dev info string '%s' '%s'" > - " '%s'\n", __func__, vendor, model, > - strflags); > + pr_err("%s: bad dev info string '%s' '%s' '%s'\n", > + __func__, vendor, model ? model : "", > + strflags ? strflags : ""); > res = -EINVAL; > } else > res = scsi_dev_info_list_add(0 /* compatible */, vendor, Expressions like "model ? model : """ can be shortened into "model ? : """. Anyway: Reviewed-by: Bart Van Assche