Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1518077ybk; Thu, 21 May 2020 08:43:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwYaXrqUA9gCpVSPCWRPHb4hccqErf+A1WgWETNaAtHcM+JriJZBWg2fTRa43s9kzo60C2 X-Received: by 2002:a50:8dc2:: with SMTP id s2mr8409772edh.318.1590075829699; Thu, 21 May 2020 08:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590075829; cv=none; d=google.com; s=arc-20160816; b=nm+sNSToDIOVHxNc4+eg6/7H3w7ePkjnFk8b1WfCIGjr0UdDs4uLQT17hEG8SeMGDO VDexLBxNe360f33cXKnlvw9PoxwFknRBPydM46lqZIWlZ8fz4zpcxC1MjKflcVoFAX1x e8EoOZPBgBgt36g3UZm3SafUURjAzxNwCctdhFG8I6o25lnEMAVGRnTuuTCeEtK8kSr/ Ula8DD56v1y/iv6SUZw8JhoLbNx/g7w2F6FjvOvCPHa0OCLErCObik72MlKSzNqMVlGE GDdNl7LkGyGcIwE8gcTPehblK+9nD3yS57FOkTzhG0SuPKd/2X6/GL5IgqT9xZ3kTgqY eOaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=t7kKQGIL/+XUIy8BYKyhP6eLPzYXGhlw9lo6TwqgMyA=; b=KVX/9tiufclLohfMpjZphZ0EbZTDAvuV/+c53RP/Qp1tSH7l9FPgXjEJcOeJMNRKjz r6R5ric8pg00lXlAvOSZ3vJsTDw0HC2cMt5EH8IEN/SUax93cdmlNCeK+K2K6VTGhba3 Pk8sYhkEyq3YQ+akmMMDKmOXQqKSJG1sr5pQHzVRzSzHgqVZ/SZ2KfYP8cbq3dInx3pm PJWXDLA5ZKLr1rYVgDlvpDUiRynlsCRvFtb5zovSC2ZCnFtjtfD31QyEhhXHFjzPu66h nwy61InmFz87Isb7JgeKe/QrMD1eF1wBz5egdcrKLnqqJO/CZoztrsAYrlmReosKTC09 vElg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="l1/Sb2B5"; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si3451647eja.367.2020.05.21.08.43.26; Thu, 21 May 2020 08:43:49 -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=@chromium.org header.s=google header.b="l1/Sb2B5"; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728145AbgEUPln (ORCPT + 99 others); Thu, 21 May 2020 11:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbgEUPlm (ORCPT ); Thu, 21 May 2020 11:41:42 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D60FFC061A0F for ; Thu, 21 May 2020 08:41:40 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id h17so7075263wrc.8 for ; Thu, 21 May 2020 08:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=t7kKQGIL/+XUIy8BYKyhP6eLPzYXGhlw9lo6TwqgMyA=; b=l1/Sb2B5nvypUAkBTKIFKxmseFrBYGzJgZAiEZH08EkPJG07KLikxvLrN1lrztGzEl 2CcYvw/8C9cwD+l5f/vdnpyqsTdvzpWbpFgNjLsYwRy6Kt0M/9oy/rmy9Dmeu5Pse+3O IqPyAr9YObZJhacol6137kvWDN0EtPUfiVwFo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=t7kKQGIL/+XUIy8BYKyhP6eLPzYXGhlw9lo6TwqgMyA=; b=dk/93uZ4+jFTuSWZkU/Yy+sWeuWMSGaojaqAJZoqvThOQIiFAZF+7q1kK06WO5WW4+ KJn28X4foFtgCxYVtcrKRrZcgUOxfpnalVmpTNH7+7LqCHIRIwzSpCCcJaCRE+iEwn4r 8L+7636QIK3V0trYNCvHTY0nHAf9NxuYA+ctUW8bRI1lC4Ycw5Q6/VQrDFhvw+dy9J8U N5wOmF0tdllsuPPz6SvYOrKvvNZGyzFd58IiOFxeNvFuEly48d71iZPB6ZxBgkvY0tVX S90wt5G6yfiLddcNFKDTI6OOKZaMQAjerKGq30/AbFnPRZf+2cp4kFYRkkJ2rvXWbuPH fGvA== X-Gm-Message-State: AOAM532K3Jw+Yk9GBjPHZouODV1kLJ6XFngotUS/Yuq90/99FB+1BtdS pZgISH1Bk3Yi4oUYT0wUaKBlxg== X-Received: by 2002:adf:e682:: with SMTP id r2mr8576889wrm.378.1590075699420; Thu, 21 May 2020 08:41:39 -0700 (PDT) Received: from chromium.org (205.215.190.35.bc.googleusercontent.com. [35.190.215.205]) by smtp.gmail.com with ESMTPSA id x1sm6508480wrt.86.2020.05.21.08.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 08:41:38 -0700 (PDT) Date: Thu, 21 May 2020 15:41:37 +0000 From: Tomasz Figa To: Xia Jiang Cc: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Rick Chang , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Marek Szyprowski , srv_heupstream@mediatek.com, senozhatsky@chromium.org, mojahsu@chromium.org, drinkcat@chromium.org, maoguang.meng@mediatek.com, sj.huang@mediatek.com Subject: Re: [PATCH v8 07/14] media: platform: Use kernel native functions for improving code quality Message-ID: <20200521154137.GG209565@chromium.org> References: <20200403094033.8288-1-xia.jiang@mediatek.com> <20200403094033.8288-8-xia.jiang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200403094033.8288-8-xia.jiang@mediatek.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Xia, On Fri, Apr 03, 2020 at 05:40:26PM +0800, Xia Jiang wrote: Thank you for the patch. Please see my comments inline. nit: I'd remove "for improving code quality" from the subject, as it's obvious that we don't intend to make the code quality worse. ;) On the contrary, I'd make it more specific, e.g. media: mtk-jpeg: Use generic rounding helpers WDYT? > Use clamp() to replace mtk_jpeg_bound_align_image() and round() to > replace mtk_jpeg_align(). > > Signed-off-by: Xia Jiang > --- > v8: no changes > --- > .../media/platform/mtk-jpeg/mtk_jpeg_core.c | 41 +++++-------------- > .../media/platform/mtk-jpeg/mtk_jpeg_core.h | 8 ++-- > drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c | 8 ++-- > drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h | 5 --- > 4 files changed, 19 insertions(+), 43 deletions(-) > > diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > index 2fa3711fdc9b..4e64046a6854 100644 > --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > @@ -157,25 +157,6 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx, > return NULL; > } > > -static void mtk_jpeg_bound_align_image(u32 *w, unsigned int wmin, > - unsigned int wmax, unsigned int walign, > - u32 *h, unsigned int hmin, > - unsigned int hmax, unsigned int halign) > -{ > - int width, height, w_step, h_step; > - > - width = *w; > - height = *h; > - w_step = 1 << walign; > - h_step = 1 << halign; > - > - v4l_bound_align_image(w, wmin, wmax, walign, h, hmin, hmax, halign, 0); > - if (*w < width && (*w + w_step) <= wmax) > - *w += w_step; > - if (*h < height && (*h + h_step) <= hmax) > - *h += h_step; > -} > - > static void mtk_jpeg_adjust_fmt_mplane(struct mtk_jpeg_ctx *ctx, > struct v4l2_format *f) > { > @@ -218,25 +199,25 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f, > if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) { > struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0]; > > - mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH, > - MTK_JPEG_MAX_WIDTH, 0, > - &pix_mp->height, MTK_JPEG_MIN_HEIGHT, > - MTK_JPEG_MAX_HEIGHT, 0); > + pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT, > + MTK_JPEG_MAX_HEIGHT); > + pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH, > + MTK_JPEG_MAX_WIDTH); > > memset(pfmt->reserved, 0, sizeof(pfmt->reserved)); > pfmt->bytesperline = 0; > /* Source size must be aligned to 128 */ > - pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128); > + pfmt->sizeimage = round_up(pfmt->sizeimage, 128); > if (pfmt->sizeimage == 0) > pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE; > goto end; > } > > /* type is MTK_JPEG_FMT_TYPE_CAPTURE */ > - mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH, > - MTK_JPEG_MAX_WIDTH, fmt->h_align, > - &pix_mp->height, MTK_JPEG_MIN_HEIGHT, > - MTK_JPEG_MAX_HEIGHT, fmt->v_align); > + pix_mp->height = clamp(round_up(pix_mp->height, fmt->v_align), > + MTK_JPEG_MIN_HEIGHT, MTK_JPEG_MAX_HEIGHT); > + pix_mp->width = clamp(round_up(pix_mp->width, fmt->h_align), > + MTK_JPEG_MIN_WIDTH, MTK_JPEG_MAX_WIDTH); > > for (i = 0; i < fmt->colplanes; i++) { > struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i]; > @@ -751,8 +732,8 @@ static void mtk_jpeg_set_dec_src(struct mtk_jpeg_ctx *ctx, > { > bs->str_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0); > bs->end_addr = bs->str_addr + > - mtk_jpeg_align(vb2_get_plane_payload(src_buf, 0), 16); > - bs->size = mtk_jpeg_align(vb2_plane_size(src_buf, 0), 128); > + round_up(vb2_get_plane_payload(src_buf, 0), 16); > + bs->size = round_up(vb2_plane_size(src_buf, 0), 128); > } > > static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx, > diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h > index 999bd1427809..28e9b30ad5c3 100644 > --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h > +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h > @@ -21,10 +21,10 @@ > #define MTK_JPEG_FMT_TYPE_OUTPUT 1 > #define MTK_JPEG_FMT_TYPE_CAPTURE 2 > > -#define MTK_JPEG_MIN_WIDTH 32 > -#define MTK_JPEG_MIN_HEIGHT 32 > -#define MTK_JPEG_MAX_WIDTH 8192 > -#define MTK_JPEG_MAX_HEIGHT 8192 > +#define MTK_JPEG_MIN_WIDTH 32U > +#define MTK_JPEG_MIN_HEIGHT 32U > +#define MTK_JPEG_MAX_WIDTH 8192U > +#define MTK_JPEG_MAX_HEIGHT 8192U This change is not mentioned in the commit message. It should go to a separate patch, possibly merged with other really minor stylistic changes like this, e.g. patch 08/14. Otherwise the patch looks good, so after addressing the above minor changes please feel free to add Reviewed-by: Tomasz Figa Best regards, Tomasz