From patchwork Sun Apr 9 19:51:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9671775 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 B5D57600CB for ; Sun, 9 Apr 2017 19:52:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A204B209D8 for ; Sun, 9 Apr 2017 19:52:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96979228C9; Sun, 9 Apr 2017 19:52:07 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 45D01209D8 for ; Sun, 9 Apr 2017 19:52:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752537AbdDITvy (ORCPT ); Sun, 9 Apr 2017 15:51:54 -0400 Received: from mout.web.de ([212.227.17.12]:51118 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752391AbdDITvx (ORCPT ); Sun, 9 Apr 2017 15:51:53 -0400 Received: from [192.168.1.2] ([77.181.114.244]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Lj2I6-1cMKhJ1vuY-00dJiI; Sun, 09 Apr 2017 21:51:48 +0200 Subject: [PATCH 4/5] target: Use kmalloc_array() in compare_and_write_callback() From: SF Markus Elfring To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Bart Van Assche , "Nicholas A. Bellinger" Cc: LKML , kernel-janitors@vger.kernel.org References: <337dfdee-8a9f-9bb3-639a-ea47758966f1@users.sourceforge.net> Message-ID: <4629f13b-fd09-8d27-8cd4-3440f13207b0@users.sourceforge.net> Date: Sun, 9 Apr 2017 21:51:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <337dfdee-8a9f-9bb3-639a-ea47758966f1@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:ef8csj0vuF/r8mNwBnzdjmYY3QewyjTO11g8+TIs93icqABLoxi KSSADUkA8GG1UdIV2mMpjABaViq16GsAA3MPeHChHEm6XEoaKHJj0foEolGHHBxE99Zw1nq Rmlv+flUuj0nx4xtKGdygMGu7eei3X2wj78XpN28TjlDb/Ozsi2pxvprzQHUvurW6tVUtYT XHyurc2O22nURw3Kt1GRQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Zm7ZBA+sQck=:qa2MWG5DgNvlhUKweuX/Cj QfDtyZFmKAN+IKrM4f06xpbHKs010VqV+ovPwb6qWw4R8fs59lL+vmdzbHey1ES4RHG0DUq/3 aS+svdSIFa5lJipET6MFNzKnZSZi0Y0NQ+uhvDlDkddIvWR8AlyRDXFGIm0dC5hJEE6UhTosS xU4RhskyOaOy+zqNsZ4sekOdN4hwtpnuyCn7zPSQgriRy/ro4oTWj2mFusHPvGduoWLadONiS P+6/qUfQiyX834+O336jQ2PdZ3oHvYUdyc8MqtYh3MkZ6pxSPRpeuHfWl8+2mJAvZEZiANQM9 Ka7Rb59ZlDV9Y6IGL2rIjKoN8dBd165iJADQjQ02eeDIfKhWpc4N2jLvImgkY9Cj8dW/dPK/B 8ta58OR2DUDtB0K1sQ9M30yT+VjZGH0M39/rGYC5VQ29Y3qKDcdZZfbWlxuqyvEsTS6VmN9iX qDTwct3uMBwq8sXQist/LMg1itBgVB8JDMrzKBEiTFypdqOEaBlj7GxlQVLUGcMRk6hDLJDp2 Q7f1PbzoaRDp21nVwnxjCM8Tjd69x9Ib6befLL49TNP05Jn3sGrL3VHgTk0KrojEhO8hPSGir 6ikJxf5Kz49nu6Au+AWjs+3jLiJatORzsPlMIsxddi3TCBTEpKyb/bgnjbjDpQaEzsdDLm0fs eyRC0A0JIvq3yt5Zs++AGNyAoyzrZxsXg9EWn3eBc6O81UMMqCn0zFBWJ0owPXHwuh1e5rlcG PJv46Bjh6d50a3FDo9ahU2tVwOaXMcb8vb9PWEHlId2MURXQ+Q43JYZlYA8BP152z2xfU2Vay xEawG1z Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 9 Apr 2017 20:25:11 +0200 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- drivers/target/target_core_sbc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index ee35c90e3b8d..a7fa4a7339db 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -519,8 +519,8 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool succes goto out; } - write_sg = kmalloc(sizeof(struct scatterlist) * cmd->t_data_nents, - GFP_KERNEL); + write_sg = kmalloc_array(cmd->t_data_nents, sizeof(*write_sg), + GFP_KERNEL); if (!write_sg) { pr_err("Unable to allocate compare_and_write sg\n"); ret = TCM_OUT_OF_RESOURCES;