Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1626235pxp; Sat, 12 Mar 2022 16:26:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1ZX4ImGrQ/PLTqj9wRDTkKhKKH66TilCo/MGbqEDVzXBUx3kfDpQjdUDa6JQYwZ8z+QXk X-Received: by 2002:a17:90b:4f8f:b0:1bf:84ad:1fe6 with SMTP id qe15-20020a17090b4f8f00b001bf84ad1fe6mr17885936pjb.189.1647131182717; Sat, 12 Mar 2022 16:26:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647131182; cv=none; d=google.com; s=arc-20160816; b=QtwNxnyXvCcsnrMF+yoABZToISMY4IaVXc3MvU+ZWnALO4stohOGFIg3MOC0qSzt0l UvTfS+o0YuKiJ1U+ybhOxSCqI4F3K99jp/zxXWSgYGZc37S1JeG2PHZEiiUzK1nBZI2U ljUHXMsxIv9i+/LUtJukBdWHWFuPhNKP9TvLhhL/kuzqIxoKv80lqPJA7h2dal+Z7L1q 5SdB0uvoUu3s9uyQLk59fV+nOldBmwohBb0rXppAeegbWBVxyU2aBzMUqg32KMPHaOUf hIB2MJ3La0SuaIZAdNcVlX+b0FD4jA9uLKVa8MIezLtZyWNd7vzUxJwYvLjXB5+6j1Ba luSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=1xX6m7maqJLmZyW32NaxaiPZ6O1tqNAYkIzpjmsF0pc=; b=QwybpPMu22orJKIizNcBmF8Z1tjDP/F+9PBYUqSspw+WnXdz8GVMcWNSam6/tq/rX5 8vBEK1QmigLHlz7sUm/Ijmr/zsKwpKQTTXLDBAHWuTm8npckW0rlDOHNIBHlqGsNEYZM KJ1Ur8ZmMoihLX26rdl0YVM1i3tWr6ADs7M3uuHfImY4/3e7sVftwSjJvZDMXzlep+Ji JQvKFdDehF0rYCrJW9lpPfiRy8Mf4sDPXPMuAQRaagaZ2SGzNe204WEnk4Tn1oOU3SLG soDoooWBwTmNPP0G2OHSNnnG1NYEHW3MBUC16JwapRrwVbrffEXYph64JncZQ7dghJOk PaPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mEdLC06R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x18-20020a170902ec9200b00151cacdd311si12199558plg.316.2022.03.12.16.26.08; Sat, 12 Mar 2022 16:26:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mEdLC06R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232530AbiCLTv5 (ORCPT + 99 others); Sat, 12 Mar 2022 14:51:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229908AbiCLTv4 (ORCPT ); Sat, 12 Mar 2022 14:51:56 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E384673DF; Sat, 12 Mar 2022 11:50:41 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id n19so20597445lfh.8; Sat, 12 Mar 2022 11:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=1xX6m7maqJLmZyW32NaxaiPZ6O1tqNAYkIzpjmsF0pc=; b=mEdLC06RPfSimrlPnyEi8F6/dnUwF03x4mlJeXaB3HvVJSRdTAFFPvz1uOGf4p/iJn MNRFyuyNaFMZrLbyWShFqnyP8OX3r1p4LNM5Sy2yn1o77Z+g9XB9F6XEi0mt8p2RUxkx VP+Q8G16+Gn5DSU/LaXXwua7bZZ5T1k4hJWxRsX6ctB35psDihocwnJyUkAhoNmGI0we 4evuu4m8fYUxncUxm5/MEdMo+kEFxNmKL9Ii/gVvES8YmbAkpwDuCYtsxjIXM01nGxqH 2BNd0948eri3pen151EMR6djSkXb+MEXmo3Fy7/c+wwk6msUAOR1iJCZjhkpvQ1dH0Vs Gu2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=1xX6m7maqJLmZyW32NaxaiPZ6O1tqNAYkIzpjmsF0pc=; b=4AuTfqVppg1aELvjkAciIHwEUj9Q0m8+rN68x0fB4UEhfoUdwD4mirHlj1haFEatLx z1eLS+n+eHx8O/X3Uw/k8a68SvkIy8iHtV2znWBgMolaMZuVTMZt0uwWJG1XmONIAN4s 51Z5y5SP608/j9iIt/gzaK1eN4wxBwajqlG2nu32gF0WR6CJlS9hFmEoJGf4f/ex8Azs me2YL+6Xt8dnDyDzOWjOwclLvP7OmqIwuCtDZdckwoFrHJ/82302ewbSR+Wtr6bPMIMH YNxezYN7I/mObOfYzlDsOufFxtVGZEkG9kjHodRv1mDKw0rnSsoMGEhxSSCtu08Gxmob CM7w== X-Gm-Message-State: AOAM531IVNSRhVGCwb4wIn/aimy13XC8+O4ePbhpLxBZ7LXDLBFev+bX klM77I6cCtAY76vtbMmTNqI= X-Received: by 2002:a05:6512:1105:b0:448:8f4e:d5d0 with SMTP id l5-20020a056512110500b004488f4ed5d0mr317084lfg.182.1647114639435; Sat, 12 Mar 2022 11:50:39 -0800 (PST) Received: from [192.168.1.11] ([94.103.229.107]) by smtp.gmail.com with ESMTPSA id p12-20020a056512138c00b0044833f1cd85sm2342644lfa.62.2022.03.12.11.50.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 12 Mar 2022 11:50:38 -0800 (PST) Message-ID: <11fa30cb-9b56-ab8c-1352-279052945432@gmail.com> Date: Sat, 12 Mar 2022 22:50:37 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] media: stkwebcam: move stk_camera_read_reg() scratch buffer to struct stk_camera Content-Language: en-US To: trix@redhat.com, mchehab@kernel.org, hverkuil-cisco@xs4all.nl, cai.huoqing@linux.dev, xose.vazquez@gmail.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220312173049.1410977-1-trix@redhat.com> From: Pavel Skripkin In-Reply-To: <20220312173049.1410977-1-trix@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Trix, On 3/12/22 20:30, trix@redhat.com wrote: > From: Tom Rix > > In stk_camera_read_reg() a single byte buffer is alloc-ed and > freed on every function call. Since the size is known, > move the buffer to the struct stk_camera where it will be alloc-ed > and freed once. > > Signed-off-by: Tom Rix > --- > drivers/media/usb/stkwebcam/stk-webcam.c | 11 ++--------- > drivers/media/usb/stkwebcam/stk-webcam.h | 2 ++ > 2 files changed, 4 insertions(+), 9 deletions(-) > > diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c > index 5b822214ccc5c..787edb3d47c23 100644 > --- a/drivers/media/usb/stkwebcam/stk-webcam.c > +++ b/drivers/media/usb/stkwebcam/stk-webcam.c > @@ -150,25 +150,18 @@ int stk_camera_write_reg(struct stk_camera *dev, u16 index, u8 value) > int stk_camera_read_reg(struct stk_camera *dev, u16 index, u8 *value) > { > struct usb_device *udev = dev->udev; > - unsigned char *buf; > int ret; > > - buf = kmalloc(sizeof(u8), GFP_KERNEL); > - if (!buf) > - return -ENOMEM; > - > ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), > 0x00, > USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, > 0x00, > index, > - buf, > + &dev->read_reg_scratch, > sizeof(u8), > 500); Wouldn't it be better to move to modern USB API like usb_control_msg_recv()? This API does not require buffer to be allocated via kmalloc(), so you will be able to use value directly. With regards, Pavel Skripkin