media: staging: media: tegra-vde: Manually pack UAPI structures
authorDmitry Osipenko <digetx@gmail.com>
Sun, 2 Jun 2019 21:37:10 +0000 (17:37 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Fri, 21 Jun 2019 21:24:05 +0000 (17:24 -0400)
The __packed macro isn't available in userspace with the kernel headers.
Checkpatch asks to use the macro, which is unwanted in a case of a UAPI
header. There is no much benefit in a tight packing of the structures,
hence let's pack them manually to cleanup things a tad. Note that there
is no old-stable userspace that will suffer from this change, hence it's
fine to change the ABI. In a result also more space is reserved for a
possible future expansion of the UAPI as it was already shown that more
fields will be needed for a later SoC generations.

Suggested-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/staging/media/tegra-vde/tegra-vde.c
drivers/staging/media/tegra-vde/uapi.h

index a5020db..cc4244d 100644 (file)
@@ -795,7 +795,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
 {
        struct device *dev = vde->miscdev.parent;
        struct tegra_vde_h264_decoder_ctx ctx;
-       struct tegra_vde_h264_frame frames[17];
+       struct tegra_vde_h264_frame *frames;
        struct tegra_vde_h264_frame __user *frames_user;
        struct video_frame *dpb_frames;
        struct dma_buf_attachment *bitstream_data_dmabuf_attachment;
@@ -830,11 +830,17 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
        if (ret)
                return ret;
 
+       frames = kmalloc_array(ctx.dpb_frames_nb, sizeof(*frames), GFP_KERNEL);
+       if (!frames) {
+               ret = -ENOMEM;
+               goto release_bitstream_dmabuf;
+       }
+
        dpb_frames = kcalloc(ctx.dpb_frames_nb, sizeof(*dpb_frames),
                             GFP_KERNEL);
        if (!dpb_frames) {
                ret = -ENOMEM;
-               goto release_bitstream_dmabuf;
+               goto free_frames;
        }
 
        macroblocks_nb = ctx.pic_width_in_mbs * ctx.pic_height_in_mbs;
@@ -955,6 +961,9 @@ release_dpb_frames:
 free_dpb_frames:
        kfree(dpb_frames);
 
+free_frames:
+       kfree(frames);
+
 release_bitstream_dmabuf:
        tegra_vde_detach_and_put_dmabuf(bitstream_data_dmabuf_attachment,
                                        bitstream_sgt, DMA_TO_DEVICE);
index dd3e4a8..ffb4983 100644 (file)
@@ -21,40 +21,42 @@ struct tegra_vde_h264_frame {
        __u32 frame_num;
        __u32 flags;
 
-       __u32 reserved;
-} __attribute__((packed));
+       // Must be zero'ed
+       __u32 reserved[6];
+};
 
 struct tegra_vde_h264_decoder_ctx {
        __s32 bitstream_data_fd;
        __u32 bitstream_data_offset;
 
        __u64 dpb_frames_ptr;
-       __u dpb_frames_nb;
-       __u dpb_ref_frames_with_earlier_poc_nb;
+       __u32 dpb_frames_nb;
+       __u32 dpb_ref_frames_with_earlier_poc_nb;
 
        // SPS
-       __u baseline_profile;
-       __u level_idc;
-       __u log2_max_pic_order_cnt_lsb;
-       __u log2_max_frame_num;
-       __u pic_order_cnt_type;
-       __u direct_8x8_inference_flag;
-       __u pic_width_in_mbs;
-       __u pic_height_in_mbs;
+       __u32 baseline_profile;
+       __u32 level_idc;
+       __u32 log2_max_pic_order_cnt_lsb;
+       __u32 log2_max_frame_num;
+       __u32 pic_order_cnt_type;
+       __u32 direct_8x8_inference_flag;
+       __u32 pic_width_in_mbs;
+       __u32 pic_height_in_mbs;
 
        // PPS
-       __u pic_init_qp;
-       __u deblocking_filter_control_present_flag;
-       __u constrained_intra_pred_flag;
-       __u chroma_qp_index_offset;
-       __u pic_order_present_flag;
+       __u32 pic_init_qp;
+       __u32 deblocking_filter_control_present_flag;
+       __u32 constrained_intra_pred_flag;
+       __u32 chroma_qp_index_offset;
+       __u32 pic_order_present_flag;
 
        // Slice header
-       __u num_ref_idx_l0_active_minus1;
-       __u num_ref_idx_l1_active_minus1;
+       __u32 num_ref_idx_l0_active_minus1;
+       __u32 num_ref_idx_l1_active_minus1;
 
-       __u32 reserved;
-} __attribute__((packed));
+       // Must be zero'ed
+       __u32 reserved[11];
+};
 
 #define VDE_IOCTL_BASE                 ('v' + 0x20)