Skip to content

Commit

Permalink
Avoid implicit type conversion losing precision
Browse files Browse the repository at this point in the history
  • Loading branch information
klogg committed May 10, 2024
1 parent bb212da commit 8ab16f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
11 changes: 6 additions & 5 deletions bridge/it66121_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ static void it66121_intr_work(struct work_struct *work_item)

static int it66121_get_edid_block(void *context, u8 *buf, unsigned int block, size_t len)
{
int i, ret, remain = len, offset = block & 1 ? 128 : 0;
int i, ret, offset = block & 1 ? 128 : 0;
size_t remain = len;
unsigned int rd_fifo_val, segment = block >> 1;
static const u8 header[EDID_LOSS_LEN] = { 0x00, 0xFF, 0xFF };
struct it66121_priv *priv = context;
Expand All @@ -344,7 +345,7 @@ static int it66121_get_edid_block(void *context, u8 *buf, unsigned int block, si

while (remain > 0) {
/* Add bytes that will be lost during EDID read */
int size = remain + EDID_LOSS_LEN;
size_t size = remain + EDID_LOSS_LEN;

/* ... and check size fits FIFO */
size = size > EDID_FIFO_SIZE ? EDID_FIFO_SIZE : size;
Expand All @@ -362,7 +363,7 @@ static int it66121_get_edid_block(void *context, u8 *buf, unsigned int block, si
ret = regmap_write(priv->regmap, IT66121_DDC_OFFSET, offset - EDID_LOSS_LEN);
if (ret)
break;
ret = regmap_write(priv->regmap, IT66121_DDC_SIZE, size);
ret = regmap_write(priv->regmap, IT66121_DDC_SIZE, (unsigned int)size);
if (ret)
break;
ret = regmap_write(priv->regmap, IT66121_DDC_SEGMENT, segment);
Expand Down Expand Up @@ -724,7 +725,7 @@ static int it66121_regs_init(struct it66121_priv *priv, struct i2c_client *clien
{
priv->regmap = devm_regmap_init_i2c(client, &it66121_regmap_config);
if (IS_ERR(priv->regmap))
return PTR_ERR(priv);
return (int)PTR_ERR(priv->regmap);

priv->irq_pending =
devm_regmap_field_alloc(&client->dev, priv->regmap, IT66121_SYS_STATUS_irq_pending);
Expand Down Expand Up @@ -850,7 +851,7 @@ static int __init it66121_probe(void)

priv->client = it66121_i2c_init();
if (IS_ERR(priv->client)) {
ret = PTR_ERR(priv->client);
ret = (int)PTR_ERR(priv->client);
pr_err("Cannot find IT66121 I2C client");
kfree(priv);
return ret;
Expand Down
11 changes: 5 additions & 6 deletions fl2000_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ static const u32 fl2000_pixel_formats[] = {
#define FL2000_BULK_BW_SUPER_SPEED (5000000000ull * 100 / FL2000_BULK_BW_PERCENT / 8)
#define FL2000_BULK_BW_SUPER_SPEED_PLUS (10000000000ull * 100 / FL2000_BULK_BW_PERCENT / 8)

static u32 fl2000_get_bytes_pix(enum usb_device_speed speed, u32 pixclock)
static unsigned int fl2000_get_bytes_pix(enum usb_device_speed speed, unsigned int pixclock)
{
int bytes_pix;
u64 max_bw;
unsigned int bytes_pix, max_bw;

/* Calculate maximum bandwidth, bytes per second */
switch (speed) {
Expand Down Expand Up @@ -267,7 +266,7 @@ static enum drm_mode_status fl2000_display_mode_valid(struct drm_simple_display_
if (fl2000_mode_calc(mode, &adjusted_mode, &pll))
return MODE_BAD;

if (!fl2000_get_bytes_pix(usb_dev->speed, adjusted_mode.clock))
if (fl2000_get_bytes_pix(usb_dev->speed, adjusted_mode.clock) == 0)
return MODE_BAD;

return MODE_OK;
Expand Down Expand Up @@ -363,7 +362,7 @@ static void fl2000_output_mode_set(struct drm_encoder *encoder, struct drm_displ
struct usb_device *usb_dev = drm_if->usb_dev;
struct fl2000_timings timings;
struct fl2000_pll pll;
u32 bytes_pix;
unsigned int bytes_pix;

/* Get PLL configuration and cehc if mode adjustments needed */
if (fl2000_mode_calc(mode, adjusted_mode, &pll))
Expand Down Expand Up @@ -453,7 +452,7 @@ int fl2000_drm_bind(struct device *master)
drm_if = devm_drm_dev_alloc(master, &fl2000_drm_driver, struct fl2000_drm_if, drm);
if (IS_ERR(drm_if)) {
dev_err(master, "Cannot allocate DRM structure (%ld)", PTR_ERR(drm_if));
return PTR_ERR(drm_if);
return (int)PTR_ERR(drm_if);
}
drm = &drm_if->drm;
drm_if->usb_dev = usb_dev;
Expand Down
16 changes: 8 additions & 8 deletions fl2000_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct fl2000_stream_buf {
struct list_head list;
struct sg_table sgt;
struct page **pages;
int nr_pages;
unsigned int nr_pages;
void *vaddr;
};

Expand All @@ -40,7 +40,7 @@ struct fl2000_stream {
struct list_head wait_list;
spinlock_t list_lock; /* List access from bh and interrupt contexts */
size_t buf_size;
int bytes_pix;
u32 bytes_pix;
struct work_struct work;
struct workqueue_struct *work_queue;
struct semaphore work_sem;
Expand All @@ -64,11 +64,11 @@ static void fl2000_free_sb(struct fl2000_stream_buf *sb)
kfree(sb);
}

static struct fl2000_stream_buf *fl2000_alloc_sb(size_t size)
static struct fl2000_stream_buf *fl2000_alloc_sb(unsigned int size)
{
int i, ret;
struct fl2000_stream_buf *sb;
int nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
unsigned int nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;

sb = kzalloc(sizeof(*sb), GFP_KERNEL);
if (!sb)
Expand Down Expand Up @@ -115,7 +115,7 @@ static void fl2000_stream_put_buffers(struct fl2000_stream *stream)
}
}

static int fl2000_stream_get_buffers(struct fl2000_stream *stream, size_t size)
static int fl2000_stream_get_buffers(struct fl2000_stream *stream, unsigned int size)
{
int i, ret;
struct fl2000_stream_buf *cur_sb;
Expand Down Expand Up @@ -220,7 +220,7 @@ static void fl2000_stream_work(struct work_struct *work)
* transfer_buffer field of URB which is unused due to SGT
*/
usb_fill_bulk_urb(data_urb, usb_dev, usb_sndbulkpipe(usb_dev, 1), cur_sb,
stream->buf_size, fl2000_stream_data_completion, stream);
(int)stream->buf_size, fl2000_stream_data_completion, stream);
data_urb->interval = 0;
data_urb->sg = cur_sb->sgt.sgl;
data_urb->num_sgs = cur_sb->sgt.nents;
Expand Down Expand Up @@ -296,10 +296,10 @@ void fl2000_stream_compress(struct fl2000_stream *stream, void *src, unsigned in
int fl2000_stream_mode_set(struct fl2000_stream *stream, int pixels, u32 bytes_pix)
{
int ret;
size_t size;
unsigned int size;

/* Round buffer size up to multiple of 8 to meet HW expectations */
size = (pixels * bytes_pix + 7) & ~(size_t)7;
size = (pixels * bytes_pix + 7) & ~(unsigned int)7;

stream->bytes_pix = bytes_pix;

Expand Down

0 comments on commit 8ab16f4

Please sign in to comment.